Skip to content

Instantly share code, notes, and snippets.

@addyosmani
addyosmani / commonjs.module-boilerplate.js
Created August 20, 2011 22:51
commonjs-module-boilerplates
/*
Courtesy of Sitepen
*/
/*
First, let’s look at very lightweight, but powerful boilerplate, an adapter that will let you write a module for both AMD and CommonJS standard module systems, using AMD style dependency declarations. This combination allows us to create modules that can be used both in browser and server environments:
*/
@jaredwilli
jaredwilli / README
Created October 4, 2011 17:05 — forked from joelambert/README
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php
@aslakhellesoy
aslakhellesoy / Main.java
Created December 2, 2011 03:49
Webbit Chat Server
package yow.webbit.chat;
import org.webbitserver.*;
import org.webbitserver.handler.StaticFileHandler;
import org.webbitserver.handler.logging.LoggingHandler;
import org.webbitserver.handler.logging.SimpleLogSink;
import org.webbitserver.netty.NettyWebServer;
import java.io.IOException;
import java.util.HashSet;
@aslakhellesoy
aslakhellesoy / Makefile
Created December 22, 2011 13:22
Publish NPM packages with Make
NAME := $(shell node -e "console.log(JSON.parse(require('fs').readFileSync('package.json', 'utf8')).name)")
VERSION := $(shell node -e "console.log(JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version)")
TARBALL := $(NAME)-$(VERSION).tgz
npm-publish:
@rm -Rf package
@mkdir package
@cp -R lib package/lib
@cp package.json package
@tar czf $(TARBALL) package
@tremby
tremby / gist:1571696
Created January 6, 2012 18:07
plot -- ascii plot of numerical input data
#!/usr/bin/env ruby
def usage(stdout = false)
stream = stdout ? $stdout : $stderr
bin = File.basename($0)
indent = " " * (bin.length() + "Usage: ".length())
stream.puts("Usage: #{bin} [--help|-h]")
stream.puts(indent + " [--vertical]")
@aslakhellesoy
aslakhellesoy / project-stats.rb
Created January 26, 2012 15:55
Small script to gather some stats about a project's volatility between releases
def info(prev_tag, tag)
`git checkout -q #{tag}`
diffstat = `git diff --stat #{prev_tag} #{tag} ./lib`.split(/\n/)[-1]
insertions = /(\d+) insertions/.match(diffstat)[1].to_i rescue 0
deletions = /(\d+) deletions/.match(diffstat)[1].to_i rescue 0
sloc = /ruby=(\d+)/m.match(`sloccount lib`)[1].to_i
changes = insertions+deletions
changetrate = changes.to_f/sloc
{
@mislav
mislav / _readme.md
Last active September 28, 2024 23:03
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

@r-lyeh-archived
r-lyeh-archived / compo.cpp
Last active December 9, 2019 06:28
Component-entity system in 16 lines of C++11. extract from kult engine (https://github.com/r-lyeh/kult)
#include <map> // Component-entity system in 16 lines of C++11. 2013 rlyeh, MIT licensed
#include <set> // Code fragment from kult engine - https://github.com/r-lyeh/kult
enum {JOIN,MERGE,EXCLUDE};using set=std::set<unsigned>;template<typename T> set&system(){
static set entities;return entities;}template<typename T,int MODE>set subsystem(const set
&B){set newset;const set&A=system<T>();if(MODE==MERGE){newset=B;for(auto&id:A)newset.ins\
ert(id);}else if(MODE==EXCLUDE){newset=B;for(auto&id:A)newset.erase(id);}else if(A.size()
<B.size()){for(auto&id:A)if(B.find(id)!=B.end())newset.insert(id);}else{for(auto&id:B)if(
A.find(id)!=A.end())newset.insert(id);}return newset;}template<typename T>std::map<unsig\
ned,T>&components(){static std::map<unsigned,T>objects;return objects;}template<typename\
T>bool has(unsigned id){return components<T>().find(id)!=components<T>().end();}templat\