Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
rochacbruno / haversine.py
Created June 6, 2012 17:43
Calculate distance between latitude longitude pairs with Python
#!/usr/bin/env python
# Haversine formula example in Python
# Author: Wayne Dyck
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@AdamAlinauskas
AdamAlinauskas / layout.htm
Created February 4, 2013 04:28
Web page layout using divs with a header, footer, right sidebar, left sidebar and an area for main content.
<html>
<head>
<style>
#header{
background-color: lightblue;
width:100%;
height:50px;
text-align: center;
}
@cgmartin
cgmartin / logging-middleware.js
Created May 24, 2015 01:43
Morgan JSON log format example
'use strict';
var morgan = require('morgan');
var os = require('os');
morgan.token('conversation-id', function getConversationId(req) {
return req.conversationId;
});
morgan.token('session-id', function getSessionId(req) {
return req.sessionId;
@chrisnolet
chrisnolet / .bash_profile
Last active September 27, 2022 13:37 — forked from henrik/.bashrc
Color-coded git branch for bash prompt
git_branch() {
local branch=$(git --no-optional-locks branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* (*\([^)]*\))*/\1/')
if [[ -n $branch ]]; then
if [[ -z $(git --no-optional-locks status --porcelain 2> /dev/null) ]]; then
echo -e " \001\033[32m\002($branch)\001\033[0m\002"
else
echo -e " \001\033[31m\002($branch)\001\033[0m\002"
fi
fi
@jbub
jbub / squash-commits.sh
Created June 12, 2013 15:31
git squash last two commits into one
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
@tkrueger
tkrueger / load-generator.js
Created August 28, 2012 16:57
generate and measure CPU load with node.js
#!/usr/bin/env node
require(__dirname+"/processor-usage.js").startWatching();
var shouldRun = true;
var desiredLoadFactor = .5;
function blockCpuFor(ms) {
var now = new Date().getTime();
var result = 0
@yorkxin
yorkxin / avoid-jquery-when-possible.md
Created July 7, 2012 13:04
Avoid jQuery When Possible

Avoid jQuery When Possible

jQuery does good jobs when you're dealing with browser compatibility. But we're living in an age that fewer and fewer people use old-school browsers such as IE <= 7. With the growing of DOM APIs in modern browsers (including IE 8), most functions that jQuery provides are built-in natively.

When targeting only modern browsers, it is better to avoid using jQuery's backward-compatible features. Instead, use the native DOM API, which will make your web page run much faster than you might think (native C / C++ implementaion v.s. JavaScript).

If you're making a web page for iOS (e.g. UIWebView), you should use native DOM APIs because mobile Safari is not that old-school web browser; it supports lots of native DOM APIs.

If you're making a Chrome Extension, you should always use native APIs, not only because Chrome has almost the latest DOM APIs available, but this can also avoid performance issue and unnecessary memory occupation (each jQuery-driven extension needs a separate

@notmasteryet
notmasteryet / hacks.js
Created July 1, 2011 05:26
Hack for IE to support pdf.js
(function() {
try {
var a = new Uint8Array(1);
return; //no need
} catch(e) { }
function subarray(start, end) {
return this.slice(start, end);
}
@robinkraft
robinkraft / gist:1413347
Created December 1, 2011 03:41
the easy way to install GDAL 1.8.0 on Ubuntu
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get -y install python-gdal