Skip to content

Instantly share code, notes, and snippets.

@macek
macek / myFirst.py
Created May 19, 2010 18:59
My First Python
def buildConnectionString(params):
"""Build a connection string from a dictionary of parameters
Returns string."""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
myParams = {
"server": "mpilgrim",
"database": "master",
"uid": "sa",
affiliate
+ referrals
| + referral
| | + player
| | | + rake
| | | + rake
| | + player
| | + rake
| + referral
| | + player
require "benchmark"
ITERATIONS = (ARGV[0] || 10000).to_i
def pick(set)
set[rand(set.size)]
end
def trial(method)
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
response = Net::HTTP.post_form(
URI.parse("http://closure-compiler.appspot.com/compile"),
{
:js_code => STDIN.read,
@macek
macek / correct_crontab.sh
Created September 24, 2010 20:37
Running Rake tasks in Engine Yard Crontab
cd /data/MyApp/current && /usr/bin/rake some:task
@macek
macek / advanced_output
Created September 24, 2010 20:44
Output Buffering with Ruby
A contents <<<
send this to a
this goes to a
a, I forgot to add this
<<<
B contents <<<
this goes to b
b, please
<<<
@macek
macek / access_default_search.rb
Created September 24, 2010 20:52
Advanced Techniques for Searchlogic 2
# your custom search
@search = Product.search(params[:search])
# searchlogic default
@search = Product.searchlogic(params[:search])
@macek
macek / .htaccess
Created September 29, 2010 21:59
Redirect without www on Nginx and Engine Yard
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@macek
macek / 20101004063749_create_photos.rb
Created October 4, 2010 22:38
How to save uploaded files to your database in Rails
# db/migrate/20101004063749_create_photos.rb
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :name, :null => false
t.binary :data, :null => false
t.string :filename
t.string :mime_type
t.timestamps
@macek
macek / Gemfile
Created November 16, 2010 01:46
Quick Sinatra App on Heroku
source 'http://rubygems.org'
gem "sinatra"