Skip to content

Instantly share code, notes, and snippets.

@samstokes
samstokes / sqlalchemy_logging.py
Created May 6, 2016
Turning on SQL logging in SQLAlchemy
View sqlalchemy_logging.py
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
View keybase.md

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 / todo
Last active Nov 2, 2018
A todo management system in a gist
View todo
#!/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"
@samstokes
samstokes / stash
Created Nov 6, 2012
example git log with a stash
View 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 Apr 18, 2012
Test public Ruby gist
View test.rb
# 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 Nov 14, 2011
DG example: bind: following links on a Google search
View dg_example_bind.rb
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|
@samstokes
samstokes / dg_loop_syntaxen.rb
Created Nov 7, 2011
DG loop combinator thinking
View dg_loop_syntaxen.rb
# Hmmm
DG::loop_until { url.present? && chunks_done < 25 }.body do
make_http_request(stuff, things, other_things).safe_callback do |blah|
blah
end
end.transform
# Yum
DG::loop_until(lambda { url.present? && chunks_done < 25 }) do
make_http_request(stuff, things, other_things).safe_callback do |blah|
@samstokes
samstokes / methods_returning.rb
Created Oct 21, 2011
Stick this in your .irbrc and smoke it
View methods_returning.rb
def methods_returning(answer, *args)
# probably want to filter out some methods
# e.g. ones that mutate their receiver...
blacklist = %w()
(methods - blacklist).select do |method|
guinea_pig = begin
clone
rescue TypeError => e
raise unless e.message =~ /can't clone/
@samstokes
samstokes / SerializableSerialization.java
Created Oct 17, 2011
One ISerialization to rule them all?
View SerializableSerialization.java
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import backtype.storm.serialization.ISerialization;
public class SerializableSerialization<T extends Serializable> implements ISerialization<T> {
@samstokes
samstokes / it_should_include_such_that.patch
Created Oct 8, 2011
[].should include_such_that {|item| p(item) }
View it_should_include_such_that.patch
commit e5e4aebccc334809c355b7387dc1469e18be2377
Author: Sam Stokes <sam@rapportive.com>
Date: Wed Oct 5 17:02:47 2011 -0700
[2, 4, 6].should_not include_such_that(&:odd?)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c6b006b..03aeec5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
You can’t perform that action at this time.