Skip to content

Instantly share code, notes, and snippets.

require 'sinatra'
require 'openssl'
require 'json'
post '/' do
body = request.body.read
puts "Time : #{Time.now}"
puts "Actual Signature : #{request.env['HTTP_X_CHARGIFY_WEBHOOK_SIGNATURE_HMAC_SHA_256']}"
puts "Computed Signature: #{signature(body)}"
@speric
speric / books.md
Created November 20, 2013 12:59
Books On The Cold War and Espionage

On the KGB, you have the Mitrokhin Archive. Several books got squeezed out of that one, including "KGB: the Untold Story."

There is an official history of MI6 out, but it deals with WWII/early Cold War. It is a multi-volume work in progress.

"Legacy of Ashes" is the CIA book, written by NYT reporter Tim Weiner. While the author tries to be comprehensive, he sticks mostly to CIA failures (because they are public). Successes are too few and/or too secret?

James Bamford's "Body of Secrets" is the better read, focusing on the NSA. Successes and failures get printed.

"Blind Man's Bluff" is a partial history of submarine-based US espionage, notable for its reliance on public documents and interviews with named persons. There are no anonymous sources quoted, ever.

@speric
speric / bialetti-tips.md
Last active December 28, 2015 08:08
Bialetti Moka Express tips

Bialetti Moka Express Tips

  • Put hot water inside the chamber just below the valve. Too much air will have your coffee pop out too fast, the process must be as slow as possible.

  • As soon as coffee starts to spill, turn down the heat to minimum and shut it off when 1/3 or 1/2 of the pot is filled. The rest will flow anyhow and you don't get a "tea-like" coffee.

  • Most important: coffee brewing with Moka or Expresso machines strongly depends on atmospheric pressure. You should grind yourself your beans accordingly to weather: good weather (high pressure) will need a finer ground, bad weather will need a coarser ground.

  • The quality of the final products depends also on the filter holes size.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@speric
speric / multisite.rb
Created November 20, 2012 19:54
Multisite Shop Example w/MongoDB
# Order class
# see http://www.slideshare.net/wonko/persisting-dynamic-data-with-mongodb-and-mongomapper
class Order
include MongoMapper::Document
key :order_id, String
class << self
def for_site(site)
klass = Class.new(self)
@speric
speric / resize.js
Created May 14, 2012 12:10
Resize w/jQuery
<script src="/javascripts/jquery.resize.js"></script>
<script>
$('.agency_talent_photo').resize(150);
</script>
@speric
speric / sendgrid.py
Created April 26, 2012 16:29
Grab bounced emails from Sendgrid
import tornado.options
import urllib2
import json
from tornado.options import define, options
if __name__ == "__main__":
define("username", help="Your Sendgrid username (usually an email address)")
define("password", help="Your Sendgrid password")
@speric
speric / x.md
Last active August 29, 2015 14:17
Summon the Ender Dragon, and ride it with a minecart

/summon Minecart ~ ~1 ~ {Riding:{id:EnderDragon}}

@speric
speric / x.md
Last active August 29, 2015 14:15
Time.zone.parse differences depending on mm dd yyyy separator character
# Rails 3.2.21, ruby 2.0.0p353

# 'American' style
> Time.zone.parse("11/12/2012 10:10")
=> Mon, 12 Nov 2012 10:10:00 EST -05:00

# 'Rest of the world' style
> Time.zone.parse("11-12-2012 10:10")
=&gt; Tue, 11 Dec 2012 10:10:00 EST -05:00
@speric
speric / trackback.php
Last active August 29, 2015 14:11
Ping WordPress trackback URLs
<html>
<head>
<title>SD News Pinger</title>
<style>
body{ font-family: Arial, sans-serif; font-size: 12px; }
</style>
</head>
<body>
<?php
date_default_timezone_set('America/New_York');