Skip to content

Instantly share code, notes, and snippets.

View yefremov's full-sized avatar

Jeff yefremov

  • Riga, Latvia
View GitHub Profile
@rivo
rivo / serve.go
Created November 26, 2017 12:28
Graceful stop and restart for HTTP servers in Go
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"os/signal"
@puppybits
puppybits / Dockerfile
Last active June 12, 2017 17:37
<10s Docker/NPM build & develop from a docker container
FROM node
RUN mkdir -p /app
WORKDIR /app
# .deps.json will only bust the cache when the package.json dependencies change
COPY .deps.json /app/package.json
RUN npm install
# cache will almost always bust here, but it's only copying files
@jin
jin / hackerrank.ml
Last active July 17, 2019 14:57
OCaml HackerRank template code
(* Enter your code here. Read input from STDIN. Print output to STDOUT *)
let () =
let ary = ref [] in
try ( while true do ary := (!ary@[read_int()]) done )
with End_of_file ->
begin
List.fold_left (fun i x ->
if (i mod 2 != 0) then (print_int(x); print_string("\n"); (i + 1))
else (i + 1)
@puppybits
puppybits / Docerfile.cacheNPM
Created September 25, 2015 18:10
Super fast JS Docker images by caching NPM modules that haven't changed
FROM library/node
MAINTAINER bobby@levelmoney.com
RUN mkdir /.npm
RUN mkdir /app
# cache (and skip if no changes) to the node_modules
WORKDIR /.npm
ADD package.json /.npm/package.json
# Set the version in the cache folder to 0.
@ctford
ctford / lenses.clj
Created July 12, 2014 20:40
A Clojure lens implementation based on focus and fmap.
(ns shades.lenses)
; We only need three fns that know the structure of a lens.
(defn lens [focus fmap] {:focus focus :fmap fmap})
(defn view [x {:keys [focus]}] (focus x))
(defn update [x {:keys [fmap]} f] (fmap f x))
; The identity lens.
(defn fapply [f x] (f x))
(def id (lens identity fapply))
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
@foca
foca / stateful.js
Created August 25, 2012 08:23
Stateful is a simple implementation of the State Pattern for JavaScript.
// Stateful is a simple implementation of the state pattern for javascript.
//
// Read more on this design pattern here:
// -> http://sourcemaking.com/design_patterns/state
//
// Initialize Stateful by passing it an object, the name of the initial state
// (defaults to "default"), and an optional hash of interfaces that will be
// applied for each state. If these interfaces are not passed, they default to
// the object's constructor's States property. So, for example:
//
@Zirak
Zirak / gist:3086939
Last active August 27, 2022 22:01
xhr for dummies

So, you want to send a motherfucking XMLHttpRequest (XHR, or commonly and falsly known as AJAX.) Too bad, just ran out of motherfucking XMLHttpRequests; but I still have one regular. XHR is not magic. It does not autofuckinmagically send things the way you want them do be sent. It does not do the thinking for you. It just sends an Http Request.

You get a hold on such a prime beast like this:

@jboner
jboner / latency.txt
Last active May 8, 2024 16:32
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD