Skip to content

Instantly share code, notes, and snippets.


Jahfer Husain jahfer

View GitHub Profile
jahfer / arraynavigation.js
Created Dec 18, 2012
Sometimes you need to look ahead or behind the current element you're on when iterating through an array. This is a neat trick for doing that quickly, without stepping outside the bounds of your array.
View arraynavigation.js
var arr = ['a','b','c'];
// -----------------------------
for (var i=0; i<arr.length; i++) {
var next = arr[ (i+1) % arr.length ]; // <= THE MAGIC
console.log(arr[i], "->", next);
jahfer / active_record_test_logger.rb
Last active Nov 26, 2019
Small tweak to output Active Record logs inside of a test with the stacktrace attached
View active_record_test_logger.rb
module MyLogSubscriber
def sql(*args)
trace = caller
Rails.backtrace_cleaner.add_silencer { |line| not line =~ /^(components)\// }
puts Rails.backtrace_cleaner.clean(trace)
puts "---------------"
jahfer / pubsub.swift
Created Jun 3, 2014
Simple pubsub implementation in Swift
View pubsub.swift
// =====================================================
enum LogLevel: Int {
case Debug = 1, Info, Error
let log_level = LogLevel.Debug
protocol Loggable {
func log()

Keybase proof

I hereby claim:

  • I am jahfer on github.
  • I am jahfer ( on keybase.
  • I have a public key whose fingerprint is 989C AA71 4413 EC42 E630 D847 EA0E 7143 55D3 C19E

To claim this, I am signing this object:

View breakpoints.scss
/* default mobile styling goes here.. */
/* then we progressively apply stylings for other widths */
/* Desktop */
@media (min-width: 767px) {
/* Tablets in Portrait */
jahfer / sse.js
Last active Dec 23, 2015
Simple SSE Server in Node (taken from somewhere online!)
View sse.js
var PORT = 8081;
var http = require("http");
var fs = require("fs");
var url = require("url");
http.createServer(function (request, response) {
var parsedURL = url.parse(request.url, true);
var pathname = parsedURL.pathname;
if (pathname === "/admin/push") {
View Golang Cross-Compile.zsh
goxc() {
echo "+-BUILD START-----------------------------------------------------------------+"
echo "Building Linux binary..."
GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o $1.linux $1.go
echo "Building OS X binary..."
go build $1.go
echo "Building Windows binary..."
GOOS=windows GOARCH=386 go build -o $1.exe $1.go
echo "+-BUILD COMPLETE--------------------------------------------------------------+"
jahfer / omitlist.js
Created Apr 26, 2013
List of common words to omit
View omitlist.js
// from:
var omit = ["able","about","above","abroad","according","accordingly","across","actually","adj","after","afterwards","again","against","ago","ahead","ain't","all","allow","allows","almost","alone","along","alongside","already","also","although","always","am","amid","amidst","among","amongst","an","and","another","any","anybody","anyhow","anyone","anything","anyway","anyways","anywhere","apart","appear","appreciate","appropriate","are","aren't","around","as","a's","aside","ask","asking","associated","at","available","away","awfully","back","backward","backwards","be","became","because","become","becomes","becoming","been","before","beforehand","begin","behind","being","believe","below","beside","besides","best","better","between","beyond","both","brief","but","by","came","can","cannot","cant","can't","caption","cause","causes","certain","certainly","changes","clearly","c'mon","co","co.","com","come","comes","concerning","consequently","consider","considering","c
View threading.go
package main
import (
func main() {
// set up our in/out pipe
nums := make(chan int, 3)
View dynamic_font_loading.js
function loadFontStyles() {
if (!window.localStorage) { return; }
var cssText;
if (cssText = localStorage.getItem('font-style-cache')) {
} else {
fetch('/css/fonts.css').then(function(cssText) {
localStorage.setItem('font-style-cache', cssText);
return cssText;
You can’t perform that action at this time.