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
/* Performs a pooling with a timeout limit and throttle frequency. | |
fn - a function that returns a promise of an async computation | |
timeout - time in milliseconds to cancel pooling (default 10s) | |
throttle - the minimumm time between pollings | |
Use throttle if the async computation is too fast and you want | |
that occurrances happens in intervals. | |
*/ | |
var polling = function(fn, timeout, throttle) { |
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
# gem install mar | |
# this only checks at runtime, so it doesn't verify the type at compilation | |
require 'mar' | |
def type_check(type, value) | |
value.is_a?(type) or raise "#{value} is not type of #{type}" | |
end | |
def type_signature(*types) |
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
var quotes = [{ symbol: 'MSFT', price: 27.01 }, | |
{ symbol: 'INTC', price: 21.75 }, | |
{ symbol: 'MSFT', price: 27.96 }, | |
{ symbol: 'MSFT', price: 31.21 }, | |
{ symbol: 'INTC', price: 22.54 }, | |
{ symbol: 'INTC', price: 20.98 }, | |
{ symbol: 'MSFT', price: 30.73 }] | |
function priceIncrease(w) { | |
return w[1].price / w[0].price - 1; |
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 | |
# Run the script as root user | |
# | |
# copy the script to the /root and chmod +x to the file. | |
# | |
# $ ./rbenv-install-system-wide.sh | |
# | |
# and wait |
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 | |
require 'socket' | |
test_file = ARGV[0] | |
socket = UNIXSocket.new('testing.sock') | |
socket.write(test_file) | |
socket.close_write |
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
# the common thinking when you are transforming some data to a non-nil value is use map | |
a = { foo: 'bar', bar: 'baz' } | |
[:foo, :bar, :baz, :foobar].map { |k| a[k] } | |
# => ['bar', 'baz', nil, nil] | |
# to drop nil cases | |
[:foo, :bar, :baz, :foobar].map { |k| a[k] }.compact | |
# => ['bar', 'baz'] |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>postMessage</title> | |
</head> | |
<body> | |
<div id="container"> | |
iFrame | |
<button>post message</button> |
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
describe "job failures" do | |
it 'retries with limited attempts' do | |
require 'resque/failure/redis' | |
Resque.unstub(:enqueue) | |
Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis] | |
Resque::Failure.backend = Resque::Failure::MultipleWithRetrySuppression | |
JobWithError = Class.new do | |
@queue = "test" |
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
.inline-block { | |
background: red; | |
margin-right: -4px; | |
} | |
.with-sidenote:after { | |
white-space: pre; | |
} |
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
/** | |
* Circular Tooltip (SO) | |
* http://stackoverflow.com/q/13132864/1397351 | |
*/ | |
* { margin: 0; padding: 0; } | |
body { | |
overflow: hidden; | |
background: url(http://theearlcarlson.com/experiments/amTooltip/img/bg.jpg); | |
} | |
/* generic styles for button & circular menu */ |