Skip to content

Instantly share code, notes, and snippets.

View mnichols's full-sized avatar

Mike Nichols mnichols

View GitHub Profile
@unicornist
unicornist / caretRangeFromPoint.js
Last active August 30, 2023 01:39
Cross browser caretRangeFromPoint
//demo: http://jsfiddle.net/heZ4z/
if (document.addEventListener) { // standard
document.addEventListener('click', function onclick(e) {
var r;
if (document.caretRangeFromPoint) { // standard (WebKit)
r = document.caretRangeFromPoint(e.pageX, e.pageY);
} else if (e.rangeParent) { // Mozilla
r = document.createRange();
@mikesmullin
mikesmullin / tcpflow-1.4.4_wrapper.coffee
Last active November 8, 2017 11:42
wrapper for tcpflow which enhances its stdout output to include easily parsed timestamp format, incl. milliseconds, tz offset, and packaged in flat json one-object-per-row ideal for mapreducing on
#!/usr/bin/env coffee
#
# install on ubuntu:
# sudo apt-get install automake autoconf libpcap-dev zlib1g-dev libboost-dev libcairo2-dev
#
# cd /tmp/
# git clone --recursive -b tcpflow-1.4.4 git@github.com:simsong/tcpflow.git tcpflow/
# cd tcpflow/
#
# sh bootstrap.sh
@insin
insin / contactform.js
Last active January 9, 2024 05:27
React contact form example
/** @jsx React.DOM */
var STATES = [
'AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI',
'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS',
'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR',
'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'
]
var Example = React.createClass({
window.onerror = function(message, url, linenumber) {
try{
_gaq.push(['_trackEvent', 'Error', 'JS', JSON.stringify({'refurl': document.location.href, 'url': url.replace(/\?\d+$/, ''), 'line': linenumber, 'message': message})]);
} catch (e) {}
return true;
};
@nickleefly
nickleefly / convert-package-to-comma-first.js
Last active December 22, 2015 00:09
convert package.json into comma first
var fs = require('fs');
var o = require('./package');
var rs = require('stream').Readable;
var out = JSON.stringify(o, null, 2)
.split(/(,\n\s+)/)
.map(function (e, i) {
return i%2 ? '\n'+e.substring(4)+' ,' : e
})
.join('');
@toddb
toddb / gist:1474205
Created December 13, 2011 22:27 — forked from mathieul/gist:966776
Require files using RequireJS before running Jasmine specs
/**
* @license Copyright (c) 2012, toddb GoneOpen Limited.
* Available via the MIT or new BSD license.
* based on https://gist.github.com/966776 (mathieul) and forked to https://gist.github.com/1474205
* jasmine.requirejs() returns a function that will load the file(s) required
* and will wait until it's done before proceeding with running specs.
* The function returned is intended to be passed to beforeEach() so the file(s)
* is(are) loaded before running each spec.
*
@dandean
dandean / backbone.model.es5properties.js
Created October 17, 2011 06:30
Monkey patch `Backbone.Model.extend()` with ES5 getters/setters for each attribute defined in the defaults.
/**
* Monkey patch `Backbone.Model.extend()` with ES5 getters/setters for each
* attribute defined in the defaults. Gives you the added bonus of being
* to pass your backbone models directly to your Mustache.js views.
*
* Example:
*
* var User = Backbone.Model.extend({
* defaults: {
* username: undefined,
@AndrewRayCode
AndrewRayCode / gist:825583
Created February 14, 2011 07:15
recursive read directory in node.js returning flattened list of files and directories
function readDir(start, callback) {
// Use lstat to resolve symlink if we are passed a symlink
fs.lstat(start, function(err, stat) {
if(err) {
return callback(err);
}
var found = {dirs: [], files: []},
total = 0,
processed = 0;
function isDir(abspath) {
@drodriguez
drodriguez / test.mm
Created December 22, 2010 22:18
Objective-C++ NSString wrapper example
// $ g++ -o test -framework Foundation -Wall test.mm
// $ ./test
// The string length is 12
// The string third char value is 108
// The string is Hello World!
#include <iostream>
#import <Foundation/Foundation.h>
class MyCppNSStringWrapper