Skip to content

Instantly share code, notes, and snippets.

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@tmcallister
tmcallister / faye.rb
Created May 23, 2012 23:52
Faye with nginx config
FAYE_TOKEN = 'secretToken'
if defined? Rails
if Rails.env == 'development'
FAYE_URI = "http://#{APP_CONFIG[:nameremoved_service][:host]}:9292/faye"
else
FAYE_URI = "https://#{APP_CONFIG[:nameremoved_service][:host]}/faye"
end
@klange
klange / _.md
Last active May 23, 2024 13:45
It's a résumé, as a readable and compilable C source file. Since Hacker News got here, this has been updated to be most of my actual résumé. This isn't a serious document, just a concept to annoy people who talk about recruiting and the formats they accept résumés in. It's also relatively representative of my coding style.

Since this is on Hacker News and reddit...

  • No, I don't distribute my résumé like this. A friend of mine made a joke about me being the kind of person who would do this, so I did (the link on that page was added later). My actual résumé is a good bit crazier.
  • I apologize for the use of _t in my types. I spend a lot of time at a level where I can do that; "reserved for system libraries? I am the system libraries".
  • Since people kept complaining, I've fixed the assignments of string literals to non-const char *s.
  • My use of type * name, however, is entirely intentional.
  • If you're using an older compiler, you might have trouble with the anonymous unions and the designated initializers - I think gcc 4.4 requires some extra braces to get them working together. Anything reasonably recent should work fine. Clang and gcc (newer than 4.4, at le
@sulmanen
sulmanen / getTwitterBearer.js
Created March 26, 2013 14:27
Get twitter API 1.1 bearer token
var request = require('request');
var consumer_key = 'YOUR_CONSUMER_KEY';
var consumer_secret = 'YOUR_CONSUMER_SECRET';
var enc_secret = new Buffer(consumer_key + ':' + consumer_secret).toString('base64');
var oauthOptions = {
url: 'https://api.twitter.com/oauth2/token',
headers: {'Authorization': 'Basic ' + enc_secret, 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
body: 'grant_type=client_credentials'
};
@jsanders
jsanders / explain_analyze.rb
Created December 18, 2013 22:56
Run EXPLAIN ANALYZE on all select queries and log the results. Definitely don't use this if performance matters...
if Rails.env.development?
require 'active_record/connection_adapters/postgresql_adapter'
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
def __explain_analyze(sql, command, *args)
meth = "#{command}_without_explain_analyze".to_sym
if /\A\s*SELECT/i.match(sql)
newsql = "EXPLAIN ANALYZE #{sql}"
plan = send(meth, newsql, *args).map { |row| row['QUERY PLAN'] }.join("\n")
Rails.logger.debug("\e[1m\e[31mQUERY PLAN FOR: #{sql.strip};\n#{plan}\e[0m")
@goldshtn
goldshtn / typelist_sort.cpp
Last active August 29, 2015 14:13
Sort a typelist by size at compile-time, using quicksort.
template <typename Predicate, typename Head, typename... Tail>
struct typelist_sort_t<Predicate, typelist<Head, Tail...>>
{
using predicate = meta_partial_apply<Predicate, Head>;
using notpredicate = meta_negate<predicate>;
using smaller_than = typelist_filter<notpredicate, typelist<Tail...>>;
using greater_than = typelist_filter<predicate, typelist<Tail...>>;
using type = typelist_cat<
typelist_sort<Predicate, smaller_than>,
typelist<Head>,
@shipleyr
shipleyr / flexbox.less
Created March 11, 2015 14:44
Can't remember exactly where I got the basic flexbox.less file from but I added new style definitions to it to cover everything I need.
// display: inline-flex //
// applies to flex container
.inline-flexbox() {
// 2009 spec
display: -webkit-box;
display: -moz-box;
display: -ms-box;
display: -o-box;
display: box;