This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SECRET_KEY=$TEST_SENDER_KEY | |
ACCESS_ID=$TEST_SENDER_TOKEN | |
API_BASE=$TEST_ENDPOINT_BASE | |
query="{\"document\":{\"recipient_id\":\"$TEST_RECIPIENT_TOKEN\",\"data\":{\"id\":\"1\",\"first_name\":\"Bill\"}}}" | |
content_md5=$(echo -n $query | openssl md5 -binary | base64) | |
content_type='application/json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = { a: 1, b: { c: 2, d: { e: 3 }}} | |
# define a recursive proc: | |
flatten_keys = -> (h, prefix = "") do | |
@flattened_keys ||= {} | |
h.each do |key, value| | |
# Here we check if there's "sub documents" by asking if the value is a Hash | |
# we also pass in the name of the current prefix and key and append a . to it | |
if value.is_a? Hash | |
flatten_keys.call value, "#{prefix}#{key}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# from the command line run: | |
# ruby ./find_hotspots.rb FILE_NAME THRESHOLD | |
class Array | |
def to_ranges | |
compact.sort.uniq.inject([]) do |r,x| | |
r.empty? || r.last.last.succ != x ? r << (x..x) : r[0..-2] << (r.last.first..x) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.hideWhenNoScrollBars = function() { | |
return this.each(function() { | |
var el = $(this), | |
target = $(el.data('target')); | |
function hideWhenNoScrollbars(target, el) { | |
if (target.scrollHeight > target.clientHeight) { // has vertical scrollbars | |
el.show(); | |
} else { | |
el.hide(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 5 10 15 20 | |
|-----|-----|-----|-----| | |
s-e---s--e--s-e---s----es | |
Intervals of 5 minutes | |
job start = s | |
job end = e | |
s should always correspond to a | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convertTemp(temp, fs, ts) | |
@conversions ||= { | |
'C' => { | |
'C' => ->(t) { t }, | |
'F' => ->(t) { t * 9 / 5 + 32 }, | |
'K' => ->(t) { t + 273.15 }, | |
'R' => ->(t) { (t + 273.15) * 9 / 5 }, | |
'De' => ->(t) { (100 - t) * 3 / 2 }, | |
'N' => ->(t) { t * 33 / 100 }, | |
'Re' => ->(t) { t * 4 / 5}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User-Agent: curl/7.21.2 (x86_64-apple-darwin) | |
Host: localhost:8080 | |
Accept: */* | |
Content-Length: 1143 | |
Expect: 100-continue | |
Content-Type: multipart/form-data; boundary=----------------------------83ff53821b7c | |
------------------------------83ff53821b7c | |
Content-Disposition: form-data; name="img"; filename="a.png" | |
Content-Type: application/octet-stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flatten a hash's keys down and format them like http form data | |
# e.g. { user: { id: 1, posts: [{ name: 'test' }] }, debug: true } | |
# becomes | |
# { 'user[id]' => 1, 'user[posts][0][name]' => 'test', 'debug' => true } | |
def convert_params_to_form_data(params, form_data = {}, prefix = '') | |
bracketeer = ->(p, k) { "#{p}#{p.empty? ? '' : '['}#{k}#{p.empty? ? '' : ']'}" } | |
params.each_with_object form_data do |(key, value), form_data| | |
case value when Hash | |
convert_params_to_form_data value, form_data, bracketeer.call(prefix, key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.lastScroll = 0; | |
$(function() { | |
var lastSnap, isAnimating, | |
snaps = $(".snap-to"), | |
$window = $(window); | |
var heights = snaps.map(function() { | |
return $(this).offset().top; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROUTES = { | |
"GET /" => ["RootController", :show], | |
"GET /home" => ["HomeController", :index], | |
"GET /posts/:slug/comments/:id/edit" => ["CommentsController", :edit], | |
"POST /posts/:slug/comments" => ["CommentsController", :create], | |
"PUT /posts/:slug" => ["PostsController", :update] | |
} | |
router = Router.new ROUTES |