Skip to content

Instantly share code, notes, and snippets.

@jish
jish / curl.sh
Created December 14, 2018 23:08
Express timeout
$ time curl -i "http://localhost:3000/never"
HTTP/1.1 503 Service Unavailable
X-Powered-By: Express
Content-Security-Policy: default-src 'self'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 704
Date: Fri, 14 Dec 2018 23:04:13 GMT
Connection: keep-alive
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jish
jish / Brocfile.js
Created June 29, 2015 20:39
Conditionally copy foo
var Funnel = require('broccoli-funnel')
var MergeTrees = require('broccoli-merge-trees')
var trees = []
var currentIndex = new Funnel('.', {
include: ['index.html'],
destDir: 'current'
})
trees.push(currentIndex)
@jish
jish / hex2base64.rb
Created April 9, 2015 02:31
hex 2 base64
input = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
expected_output = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
def six(string)
string.scan(/\w{6}/)
end
def to_binary(hex_string)
expected_length = (hex_string.length / 2) * 8
"%0#{expected_length}d" % hex_string.to_i(16).to_s(2)
@jish
jish / matches.rb
Created December 14, 2014 17:59
What are the odds or randomly selecting the burned match from a bundle of matches?
Match = Struct.new(:burned)
PEOPLE = 4
TRIALS = 1_000_000
matches = Array.new(PEOPLE-1).fill(Match.new(false)).push(Match.new(true))
results = Array.new(PEOPLE).fill(0)
TRIALS.times do
matches.shuffle!
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jish
jish / promise.js
Created October 28, 2014 22:35
An example "always" behavior for ES6 promises. This only works if you do not create / return intermediate promises.
// A thing I want to do
// This flow only involves **one** promise, for example an ajax call
// None of the subsequent `then` or `catch` calls, return new promises.
var explode = false;
var promise = new Promise(function(resolve, reject) {
if (explode) {
@jish
jish / github.com.js
Created October 10, 2014 23:00
Octocats for empty notifications
$(document).ready(function(){
if (document.location.pathname.match(/\/notifications$/)) {
var array = [
"adventure-cat",
"agendacat",
"andycat",
"baracktocat",
"bear-cavalry",
@jish
jish / keybase.md
Created April 2, 2014 18:39
keybase.md

Keybase proof

I hereby claim:

  • I am jish on github.
  • I am jish (https://keybase.io/jish) on keybase.
  • I have a public key whose fingerprint is 0B31 CDA4 60EB 610D 022B B0AB A9EF CF21 0785 9CB5

To claim this, I am signing this object:

@jish
jish / gem-public_cert.pem
Created March 6, 2014 01:00
X.509 public cert for jish
-----BEGIN CERTIFICATE-----
MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxqb3No
Lmx1YmF3YXkxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
A2NvbTAeFw0xNDAzMDYwMDU3NDhaFw0xNTAzMDYwMDU3NDhaMEMxFTATBgNVBAMM
DGpvc2gubHViYXdheTEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTyEPQdD
HcNy8UwnxBzwhnIYWaye7jS8i+wsBZxMgAoMaTdmRxFMJLUK4mP84fMFeF8LqOwJ
g+DG2g4r78KrkxYgUsvOlzpspPxUlXleldNNAGcpBxnW7CKZw3shg0KU2wn21AAF
/CVG/5AAt3uJO9L10uE7N7euwNbF3mOcI5AMlTA5qzgkl5/VwPjWWshHRaRdJEki
+L5HEqWQ31hTD2ks6CuhZZC2qeRWvSeslyujbrBNhwVu0V5V1Jp1EHPwYFM+fd92