Skip to content

Instantly share code, notes, and snippets.

# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@zachwaugh
zachwaugh / gist:521133
Created August 12, 2010 15:19
Loading rails environment in a script
#!/usr/bin/env ruby
# Load Rails
ENV['RAILS_ENV'] = ARGV[0] || 'production'
DIR = File.dirname(__FILE__)
require DIR + '/../config/environment'
# ... do stuff that requires using your rails models
@wejrowski
wejrowski / block-to-partial
Created August 17, 2011 22:10
Passing Blocks to Rails partials
<%
#
# I originally needed to create a sidebar partial that had a div area where I could place custom links into. Finally found it.
# When I was trying to figure this out before and realized I needed to pass the view into :layout, rather than just using render 'layout'. Not sure why the block can't be passed otherwise but nonetheless...
#
# For explanation of options see
# http://guides.rubyonrails.org/layouts_and_rendering.html#options-for-render
#
%>
@kidbrax
kidbrax / point-in-polygon.rb
Created September 22, 2011 22:43
Check whether a point is within a polygon #ruby
def point_in_polygon?(polygonPoints)
return false if self.latitude.blank? or self.longitude.blank?
polygonPoints.each do |point|
point[0] = point[0].to_f
point[1] = point[1].to_f
end
contains_point = false
i = -1
j = polygonPoints.size - 1
@antimatter15
antimatter15 / algorithm.pseudo
Created February 16, 2012 03:22
Pseudocode to Graphviz Converter
Place phone call.
Home?
Leave message
Wait for callback
"Would you like to share a meal"
"Would you like to share a meal"
What is the response (A) ?
"Do you enjoy a hot beverage"
What is the response (B) ?
n = 0
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active April 23, 2024 19:14
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@scottwillson
scottwillson / Tsung Rails authenticity_token
Created January 30, 2013 21:07
If you're using Tsung to test a Rails site that has CSRF protection, Tsung needs to parse the authenticity_token and submit it when POSTing. I could only find outdated examples. The snippet below works.
<request>
<dyn_variable name="authenticity_token" ></dyn_variable>
<http url="/registrations/new" version="1.1" method="GET"></http>
</request>
<request subst="true">
<http url="/registrations" method="POST" version="1.1"
contents="authenticity_token=%%_authenticity_token%%&amp;first_name=Jane"/>
</request>
@jimothyGator
jimothyGator / README.md
Last active March 21, 2024 10:08
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@willurd
willurd / web-servers.md
Last active April 25, 2024 01:54
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
@matthiasg
matthiasg / docs style (bootstrap)
Created August 5, 2013 06:26
the callouts from the bootstrap documentation
/* Side notes for calling out things
-------------------------------------------------- */
/* Base styles (regardless of theme) */
.bs-callout {
margin: 20px 0;
padding: 15px 30px 15px 15px;
border-left: 5px solid #eee;