This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBoundsZoomLevel(bounds, mapDim) { | |
var WORLD_DIM = { height: 256, width: 256 }; | |
var ZOOM_MAX = 21; | |
function latRad(lat) { | |
var sin = Math.sin(lat * Math.PI / 180); | |
var radX2 = Math.log((1 + sin) / (1 - sin)) / 2; | |
return Math.max(Math.min(radX2, Math.PI), -Math.PI) / 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function text2img($text, $size, $color, $font='kangxi.otf') { | |
$draw = new ImagickDraw(); | |
$draw->setGravity(Imagick::GRAVITY_CENTER); | |
$draw->setFont($font); | |
$draw->setFontSize($size); | |
$draw->setFillColor(new ImagickPixel($color)); | |
$im = new imagick(); | |
$metric = $im->queryFontMetrics($draw, $text); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
LISTEN_PORT = 18080 | |
from twisted.internet import protocol, reactor | |
from ProxySelector import ProxySelector | |
import csv, random | |
class ProxySelector: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# From http://markmcb.com/2013/02/04/cleanup-unused-linux-kernels-in-ubuntu/ | |
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ember.Handlebars.registerHelper('eachIndexed', function eachHelper(path, options) { | |
var keywordName = 'item', | |
fn; | |
// Process arguments (either #earchIndexed bar, or #earchIndexed foo in bar) | |
if (arguments.length === 4) { | |
Ember.assert('If you pass more than one argument to the eachIndexed helper, it must be in the form #eachIndexed foo in bar', arguments[1] === 'in'); | |
Ember.assert(arguments[0] + ' is a reserved word in #eachIndexed', $.inArray(arguments[0], ['index', 'index+1', 'even', 'odd'])); | |
keywordName = arguments[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight | |
@div.bind 'mousewheel DOMMouseScroll', (e) -> | |
d = e.originalEvent.wheelDelta or -e.originalEvent.detail | |
e.preventDefault() if ((@scrollHeight - @scrollTop) <= @clientHeight and d < 0) or (@scrollTop <= 0 and d > 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Example: ./applocale.sh QQ zh-CN | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 [app name] [locale]" | |
exit 1 | |
fi | |
CMD="/usr/bin/defaults" | |
OSASCRIPT="/usr/bin/osascript" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dog | |
for x in $argv | |
if not test -f $x | |
echo "$x does not exist or cannot be barked at" | |
else if not test -r $x | |
echo "$x cannot be read" | |
else if perl -E 'exit((-B $ARGV[0])?0:1);' $x | |
echo "$x is a binary file" | |
else | |
file $x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os | |
import socket | |
import threading | |
import workerpool | |
import json | |
from pprint import pprint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
OlderNewer