Skip to content

Instantly share code, notes, and snippets.

@samstokes
samstokes / todo
Last active March 4, 2024 00:51
A todo management system in a gist
#!/bin/bash -e
if [[ $# > 0 ]]; then
case "$1" in
-h | -\? | --help )
{
echo "Add a todo:"
echo " todo Reformulate the widget plans."
echo "See what you have to do:"
echo " todo"

Mocha Bourbon

Two-stage infusion.

Stage 1: coffee

  • ¼cup coffee beans
  • 16oz Bourbon (works with rye too)

Infuse for 24 hours, then strain into a second jar.

@samstokes
samstokes / purple-haze.md
Created July 31, 2023 07:21
Purple Haze cocktail

From Ember restaurant in Arroyo Grande, CA

  • 2oz empress 1908 gin
  • ¾oz fresh lemon juice
  • ⅜oz lavender syrup
  • ⅜oz elderflower liqueur (Fiorente or St Germain)

Shake and serve on ice in a Collins glass. Garnish: garden lavender sprig

@samstokes
samstokes / README.md
Created January 7, 2023 01:49
Handling Disqus export in Jekyll

Script to parse Disqus Comment Export XML as documented at https://help.disqus.com/en/articles/1717164-comments-export and translate it into a JSON format that is easier to handle (for example, using Jekyll's built-in support for JSON files in _data).

The imagined use case is if you have decided to remove Disqus comments from your blog (or maybe disable commenting entirely), but have existing comments on previous posts that you want to keep. You can export your comments from Disqus, and statically render the historical comments, without needing any Disqus Javascript or cookies.

The Disqus XML exports all categories, threads and posts into flat lists, with id references for parent relationships. That makes it complicated to do things like "look up all comments on this blog post", or see which comments were in reply to which,

@samstokes
samstokes / regex-groups-global.rb
Created November 18, 2009 03:28
How to extract groups from a regex match in Ruby without globals or temporary variables. Code snippets supporting http://blog.samstokes.co.uk/post/251167556/regex-style-in-ruby
if "foo@example.com" =~ /@(.*)/
$1
else
raise "bad email"
end
# => "example.com"
@samstokes
samstokes / sqlalchemy_logging.py
Created May 6, 2016 20:53
Turning on SQL logging in SQLAlchemy
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

Keybase proof

I hereby claim:

  • I am samstokes on github.
  • I am samstokes (https://keybase.io/samstokes) on keybase.
  • I have a public key ASBjVCcl1P5w4m-tmbthV5BAb3AOcY4g2Uxu3v7G6e8kXAo

To claim this, I am signing this object:

@samstokes
samstokes / stash
Created November 6, 2012 22:08
example git log with a stash
sstokes@sstokes-mba-ubuntu:gittest$ git log --all --decorate --graph --oneline
* 15e2132 (refs/stash) WIP on master: 2e83ed8 initial commit
|\
| * 61442a1 index on master: 2e83ed8 initial commit
|/
* 2e83ed8 (HEAD, master) initial commit
@samstokes
samstokes / test.rb
Created April 18, 2012 01:22
Test public Ruby gist
# This is a large amount of Ruby code
# No, really, it is
# Can't you tell?
def foo(bar)
baz(bar)
end
# That was a large amount of Ruby code
# Wiffle bamble boo
@samstokes
samstokes / dg_example_bind.rb
Created November 14, 2011 22:08
DG example: bind: following links on a Google search
EM.run do
fetch('http://google.com/search?q=deferrable_gratification').bind! do |doc|
fetch((doc / 'ol' / 'li' / 'a')[0][:href])
end.bind! do |doc|
fetch((doc / '#repository_homepage').at(:a)[:href])
end.callback do |doc|
puts doc.at(:title).inner_text
# now the previous 'doc's aren't in scope, so I can't accidentally
# refer to them
end.errback do |error|