Skip to content

Instantly share code, notes, and snippets.

@alphabet
alphabet / storagePolyfill.js
Last active May 19, 2016 15:17 — forked from jarrodirwin/storagePolyfill.js
LocalStorage/SessionStorage Polyfill with Safari Private Browsing support.
// alphabet work derived from https://gist.github.com/remy/350433
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
@alphabet
alphabet / web-servers.md
Created March 2, 2016 21:32 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@alphabet
alphabet / gist:f7485947fe4c4e6733ee
Last active September 8, 2015 15:51 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@alphabet
alphabet / config.ru
Last active September 2, 2015 13:47 — forked from nathany/config.ru
Magical Unicorn Configuration for Heroku
# add something like this to config.ru
# see https://github.com/kzk/unicorn-worker-killer
if Integer(ENV['UNICORN_KILLER'] || 0) != 0
require 'unicorn/worker_killer'
# Max memory size (RSS) per worker
use Unicorn::WorkerKiller::Oom, (350*(1024**2)), (400*(1024**2)), 30, true
end
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@alphabet
alphabet / gist:3e4f940d088525075969
Last active August 29, 2015 14:13
CQ Head Include
<script src="/etc/designs/cro/shared-resources/scripts/user-info.js"></script>
<script src="http://reactv-cq.herokuapp.com/css/bower_components/css-modal/modal.js"></script>
<!-- sitecatalyst setup -->
<script language="JavaScript">var s_account="cuconsumer,cuglobal" </script>
<script language="JavaScript" type="text/javascript" src="/etc/designs/cro/shared-resources/scripts/s_code.js"></script>
<!-- end sitecatalyst setup -->
<script>
function checkAuth() {
ipfw add pipe 1 all from any to any && sudo ipfw pipe 1 config bw 1000Kbit/s delay 100ms
@alphabet
alphabet / countrylist.json
Last active December 24, 2015 16:29
JSON list - 237 countries and their country code abbreviations, for use with backbone-forms.js
{ val: 'US', label: 'UNITED STATES'},
{ val: 'CA', label: 'CANADA'},
{ val: 'AF', label: 'AFGHANISTAN'},
{ val: 'AX', label: 'ALAND ISLANDS'},
{ val: 'AL', label: 'ALBANIA'},
{ val: 'DZ', label: 'ALGERIA'},
{ val: 'AD', label: 'ANDORRA'},
{ val: 'AO', label: 'ANGOLA'},
{ val: 'AI', label: 'ANGUILLA'},
{ val: 'AQ', label: 'ANTARCTICA'},
@alphabet
alphabet / async_pi
Last active December 20, 2015 20:08
Benchmarks for asynchronous calculation of the value of pi
require 'benchmark'
require "bigdecimal"
require "bigdecimal/math"
include BigMath
@threads = []
def asynch_pi(executions, digits)
# STDOUT.write "executions: #{executions}, digits: (#{digits})\n"
(1..executions).each do |number|