Skip to content

Instantly share code, notes, and snippets.

@clofresh
clofresh / caching_proxy.lua
Created November 8, 2008 21:09
Memcache caching layer for Mysql Proxy
require('luarocks.require')
require('md5')
require('Memcached')
local memcache = Memcached.Connect()
cache_hits = 0
cache_misses = 0
function is_query(packet)
return packet:byte() == proxy.COM_QUERY
class Lazy(type):
def __init__(cls, name, bases, dict):
super(Lazy, cls).__init__(name, bases, dict)
cls.instance = None
def check_instance(cls):
if cls.instance is None:
if hasattr(cls, 'instantiate'):
setattr(cls, 'instance', getattr(cls, 'instantiate')())
else:
def get_db():
db = getattr(get_db, 'db', db_connection())
get_db.db = db
return db
def func1():
db = get_db()
db.execute('SELECT * FROM things')
def func2():
import Image
from numpy import average, linalg, dot
import sys
images = sys.argv[1:3]
vectors = []
norms = []
for image in images:
vector = []
source :idx,
{
:file => 'listings.txt',
:parser => :delimited,
:skip_lines => 1
},
[
:listing_id,
:area,
:baths_full,
Header "%% Erliki".
Nonterminals phrase wikilink word.
Terminals string '[[' ']]' '<' '>'.
Rootsymbol phrase.
phrase -> word : '$1'.
phrase -> word phrase : ['$1', '$2'].
wikilink -> '[[' string ']]' : {'wikilink', '$2'}.
word -> wikilink : '$1'.
word -> string : '$1'.
#!/bin/bash
HOST=127.0.0.1
PORT=1978
SID=1
UPDATE_LOG_DIR=ulog/$SID
MASTER_HOST=127.0.0.1
MASTER_PORT=1979
mkdir -p $UPDATE_LOG_DIR
$clock.bpm = 80
$mutation = L{|measure| true}
$measures = 4
def note(midi_note_number)
Note.create(:channel => 2,
:number => midi_note_number,
:duration => 1,
:velocity => 100 + rand(27))
require 'java'
require 'jar-that-has-my-libaries.jar'
import com.what.DeserializationUtil
util = DeserializationUtil.new()
puts util.inspect
-- I want my code to be backwards compatible with database versions
SELECT COUNT(*)
INTO has_new_col
FROM all_tab_cols
WHERE table_name = 'UPDATED_TABLE'
AND column_name = 'NEW_COL';
IF has_new_col = 0 THEN
INSERT INTO other_table