Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / q-mongoose-so.js
Last active August 24, 2017 05:49
Q + Mongoose from StackOverflow
var mongoose = require('mongoose');
mongoose.connect('mongo://localhost/test');
var conn = mongoose.connection;
var users = conn.collection('users');
var channels = conn.collection('channels');
var articles = conn.collection('articles');
var insertUsers = Q.nfbind(users.insert.bind(users));
var insertChannels = Q.nfbind(channels.insert.bind(channels));
@jboner
jboner / latency.txt
Last active July 13, 2025 02:09
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
@lindenb
lindenb / Makefile
Created July 5, 2012 20:11
newick lex/yacc parser
all:
bison -d newick.y
flex newick.l
gcc -Wall -O3 newick.tab.c lex.yy.c
echo "(A,B,(C,D)E)F;" | ./a.out
/*
* linux 2.6.37-3.x.x x86_64, ~100 LOC
* gcc-4.6 -O2 semtex.c && ./a.out
* 2010 [email protected], salut!
*
* update may 2013:
* seems like centos 2.6.32 backported the perf bug, lol.
* jewgold to 115T6jzGrVMgQ2Nt1Wnua7Ch1EuL9WXT2g if you insist.
*/
@icastell
icastell / NetworkServiceDiscovery.java
Last active March 17, 2021 17:25
Using Network Service Discovery (Bonjour) in Android
package com.solarfighter.activities;
import java.io.IOException;
import java.net.InetAddress;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceListener;
import android.content.Context;
import os
import sys
import re
import hashlib
import csv
import time
import locale
import getopt
@branneman
branneman / better-nodejs-require-paths.md
Last active June 24, 2025 22:40
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@yanatan16
yanatan16 / pebble-discs.c
Last active August 29, 2015 13:56
Pebble Discs Walkthrough
#include <pebble.h>
#include <time.h>
static const int FACE_DISC_RADIUS = 70;
static const int CENTER_DISC_RADIUS = 20;
static const int HOUR_DISC_RADIUS = 10;
static const int MINUTE_DISC_RADIUS = 5;
static const int HOUR_ROT_RADIUS = 40;
static const int MINUTE_ROT_RADIUS = 60;
@lunny
lunny / diskinfo.go
Created March 28, 2014 08:59
Disk Info for Golang
package main
import (
"fmt"
"syscall"
)
type DiskStatus struct {
All uint64 `json:"all"`
Used uint64 `json:"used"`
@Akagi201
Akagi201 / browser.md
Last active September 8, 2016 02:54

兼容性测试

浏览器内核/渲染引擎/排版引擎/解释引擎/Rendering Engine

  • 渲染引擎主要是负责HTML, CSS以及其他一些东西的渲染.
  • 有时, 浏览器内核, 除了渲染引擎, 也悄悄包含了javascript引擎. 如: WebKit, 它由渲染引擎WebCore和Javascript引擎JSCore组成.
  • IE: Trident
  • Safari: WebKit(KHTML分支) -> WebKit2
  • Chrome/Chromium: Chromium引擎(WebKit分支) -> Blink引擎(基于WebKit2)
  • Opera: Elektra -> Presto -> Chromium引擎 -> Blink引擎