Skip to content

Instantly share code, notes, and snippets.

View blaskovicz's full-sized avatar
💻

Zach Auclair blaskovicz

💻
View GitHub Profile
@blaskovicz
blaskovicz / add_hex.js
Created October 29, 2019 19:33
addHex, nodejs
function addHex(left /*: string*/, right /*: string*/) /*: string*/ {
if (left.length < right.length) {
[left, right] = [right, left];
}
// left is "longer"
// left = a b c
// right = d
// --> add c + d,
// --> carry 1 to b + <nothing>
@blaskovicz
blaskovicz / string.spec.ts
Last active September 27, 2023 09:33
trimPrefix() and trimSuffix() in TypeScript
import {} from 'jasmine';
import {trimSuffix, trimPrefix} from './string';
describe('string utils', () => {
describe('trimSuffix', () => {
for (const [from, trim, to] of [
[null, 'abc', null],
['abc', 'c', 'ab'],
['abc', '', 'abc'],
['abc', null, 'abc'],
['abc', 'bc', 'a'],
@blaskovicz
blaskovicz / logrus_sentry_flusher.go
Last active July 1, 2018 02:38
make sure to flush async logrus_sentry hook
package main
import (
"fmt"
"time"
logsentry "github.com/evalphobia/logrus_sentry"
"github.com/sirupsen/logrus"
)
@blaskovicz
blaskovicz / template.html
Created June 30, 2017 18:01
Golang template features (nested variables, range over array, index into map, conditionals)
<div class="levels">
{{ $groups := .LevelGroups }}
{{ $groupedLevels := .Levels }}
{{ $completeLevels := .CompleteLevels }}
{{ if $groupedLevels }}
{{ range $group := $groups }}
<div class="intro"><h2>{{$group}}</h2></div>
{{ range index $groupedLevels $group }}
<a href="/level/{{.Number}}" class="{{if index $completeLevels .Number}}complete{{end}}">
<span class="level">{{.Number}} </span>
@blaskovicz
blaskovicz / survey_monkey.js
Last active July 1, 2018 02:36
Sum Survey Monkey Responses
/**
usage: copy/paste code into your console to view all numeric responses, summed, printed per question.
example output:
[1] 6180176821 => 2
...
[23] 6167268127 => 2
Total 62 for 23 items (2.6956521739130435 / item)
*/
/**
@blaskovicz
blaskovicz / stub_requests.rb
Created May 8, 2017 15:47
stubbing rails request object, mocking remote requests, and with mocha
test 'should create account' do
user = User.find_by(provider: mock_user['provider'], uid: mock_user['uid'])
assert_nil user
# mock model remote updates
stub_request(:post, "#{fixtures(:some1).api_url}/destinations")
.to_return(status: 200, body: {}.to_json, headers: {})
stub_request(:put, %r{#{fixtures(:some1).api_url}/destinations/\d+})
.to_return(status: 204, body: {}.to_json, headers: {})
@blaskovicz
blaskovicz / humanDuration.js
Last active July 22, 2024 13:58
humanDuration.js
function humanDuration(number, unit = "s") {
let result;
switch (unit) {
case "ns":
result = number / 1000000;
if (result < 1) break;
number = result;
unit = "ms";
case "ms":
result = number / 1000;