Skip to content

Instantly share code, notes, and snippets.

@macek
macek / config.mk
Created October 18, 2011 21:13
configure irssi-xmpp
LDFLAGS += -flat_namespace -undefined warning -fPIC
@macek
macek / sql_sanitizer.php
Created April 15, 2011 05:11
POS410 SQL sanitizer example
<?php
class Mysql {
static public function query(){
$args = func_get_args();
return mysql_query(call_user_func_array(array("self", "queryf"), $args));
}
static public function queryf(){
@macek
macek / Gemfile
Created November 16, 2010 01:46
Quick Sinatra App on Heroku
source 'http://rubygems.org'
gem "sinatra"
@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 / .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 / 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 / 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 / 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
#!/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,
require "benchmark"
ITERATIONS = (ARGV[0] || 10000).to_i
def pick(set)
set[rand(set.size)]
end
def trial(method)