Skip to content

Instantly share code, notes, and snippets.

💭
🤔 💡

Zach Auclair blaskovicz

💭
🤔 💡
Block or report user

Report or block blaskovicz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View add_hex.js
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 May 21, 2019
trimPrefix() and trimSuffix() in TypeScript
View string.spec.ts
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 Jul 1, 2018
make sure to flush async logrus_sentry hook
View logrus_sentry_flusher.go
package main
import (
"fmt"
"time"
logsentry "github.com/evalphobia/logrus_sentry"
"github.com/sirupsen/logrus"
)
@blaskovicz
blaskovicz / template.html
Created Jun 30, 2017
Golang template features (nested variables, range over array, index into map, conditionals)
View template.html
<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 Jul 1, 2018
Sum Survey Monkey Responses
View survey_monkey.js
/**
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
stubbing rails request object, mocking remote requests, and with mocha
View stub_requests.rb
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 Jul 31, 2018
humanDuration.js
View 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;
You can’t perform that action at this time.