Skip to content

Instantly share code, notes, and snippets.

View StarpTech's full-sized avatar

Dustin Deus StarpTech

View GitHub Profile
@domenic
domenic / README.md
Created March 29, 2012 16:01
Cross-platform git hooks for Node.js

Here's how this works:

  • Include a git_hooks/ directory in your project, with these two files (plus other hooks if you want, written in a similar style).
  • Add "npm" to your devDependencies in package.json, so that the pre-commit hook can do its magic.
  • Add test and lint scripts to your package.json, e.g.
    "scripts": {
        "test": "mocha",
 "lint": "jshint ./lib --show-non-errors"
minikube start --vm-driver=xhyve --container-runtime=docker --show-libmachine-logs --v=10 --alsologtostderr --cpus 4 --memory 8192
@timknight
timknight / breakpoint.scss
Created May 5, 2014 12:48
A simple responsive breakpoint mixin that takes both attribute names and custom widths. See https://medium.com/p/889927b37740/
@mixin breakpoint($min: 0, $max: 0) {
$type: type-of($min);
@if $type == string {
@if $min == xs {
@media (max-width: 767px) { @content; } // Mobile Devices
}
@else if $min == sm {
@media (min-width: 768px) { @content; } // Tablet Devices

Latency numbers every programmer should know

1 typical CPU instruction ..................   1 ns
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs

SSD random read ........................ 150,000 ns = 150 µs

const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},
@m0llysour
m0llysour / nginx.conf
Created September 10, 2012 16:21
nginx proxy server example
upstream my_upstream { #this line starts the list of real resources that exist behind the nginx server
server 127.0.0.1:1337;
server 127.0.0.1:1338; #these servers are used in the order they are defined, in round robin fashion. there's more ways of load balancing in the docs
server 127.0.0.1:1339 backup; #amazingness no.1, the keyword "backup" means that this server should only be used when the rest are non-responsive
keepalive 64;
}
server {
listen 80;
location /resource.html { #in my example the server only responds to requests for the file /request.html
@jashmenn
jashmenn / self-eq-this-vs-bind.md
Last active September 6, 2022 23:11
Javascript var self = this; vs. .bind

The Problem

In Javascript this is bound in unexpected ways. Functions, in particular, create a new 'this' and so when you want to keep a reference to an "outer" object you sometimes see the pattern:

var self = this;

as in:

var self = this;
@klovadis
klovadis / gist:2549131
Created April 29, 2012 10:03
How to use optional arguments in node.js
// example function where arguments 2 and 3 are optional
function example( err, optionalA, optionalB, callback ) {
// retrieve arguments as array
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
// first argument is the error object
@jorisvddonk
jorisvddonk / ApolloComplexityPlugin.ts
Last active October 9, 2022 23:01
ApolloComplexityPlugin
import { ApolloServerPlugin, GraphQLServiceContext } from "apollo-server-plugin-base";
import { GraphQLSchema, separateOperations } from "graphql";
import { fieldConfigEstimator, getComplexity, simpleEstimator } from "graphql-query-complexity";
export class ApolloComplexityPlugin implements ApolloServerPlugin {
private schema: GraphQLSchema;
constructor(private maxComplexity: number) { }
public serverWillStart(service: GraphQLServiceContext) {
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 5, 2023 21:58
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add git@github.com:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.