Skip to content

Instantly share code, notes, and snippets.

@splee
splee / gist:4677465
Last active December 11, 2015 23:29 — forked from lithix-src/gist:4677404
select count(*)
into @exists
from information_schema.tables
where table_schema = 'dbs_admin'
and table_name = 'dbs_auto_increment';
set @qry = select if(@exists<0,
'rename table publisher.dbs_auto_increment to dbs_admin.dbs_auto_increment',
'select \'table exists\' status') as querystr;
"""This is main.py, where the main stuff happens.
"""
import sys
import os
# lets assume your file is in /home/oli/nuke_files/main.py
#
# __file__ is a magic variable which python automatically populates, and is the
# full path to the file which is currently being executed (i.e. this one),
# so __file__ == '/home/oli/nuke_files/main.py'
@splee
splee / gist:1628845
Created January 17, 2012 21:02
Multi-dimensional defaultdict aggregation
def parse_line(entry, e_dict):
   leaderboard_req_re = '/api/publisher/([^/}{32}?)/proxy/.*leaderboard.*'
   regex = re.compile(leaderboard_req_re)
   e = entry.splt('\t')
   for i in e:
       if e[8] == 'loyalty.bigdoor.com':
           match = regex.search(e[19])
       if match:
           ts_slice = e_dict[e[14]]
           ts_slice[match.group(0)] += 1
@splee
splee / gist:1143348
Created August 13, 2011 01:01
Odd mock.side_effect issue
# code under test:
class TwitterOAuth(BaseOAuth):
def get_profile(self, access_token):
"""Retrieves the profile of the Twitter user who just authenticated.
Requires the raw access token from the API as Twitter returns the user
ID baked in.
"""
@splee
splee / gist:1133099
Created August 9, 2011 00:07
The Soda Algorithm
import random
from imagination import count_soda, restock_soda
available_sodas = ['Sprite', 'Coke', 'Diet Coke', 'Dr. Pepper']
def take_soda():
soda = random.choice(available_sodas)
if count_soda(soda) < 2:
restock_soda(soda)
@splee
splee / gist:1110472
Created July 27, 2011 21:57
Creating a bigdoorkit Client instance
from bigdoorkit import Client
app_key = 'BIGDOOR_APP_KEY'
secret_key = 'BIGDOOR_SECRET_KEY'
client = Client(secret_key, app_key)
@splee
splee / gist:1110450
Created July 27, 2011 21:45
Periodic Rewards - Main function
from bigdoorkit import Client
from collections import defaultdict
import restkit
def reward_users(client, currency_id, transaction_ids):
"""Rewards the top 3 leaders on a specified currency's leaderboard.
@param client {bigdoorkit.Client} The preconfigured client to access the
BigDoor API.
@param currency_id {int} ID of the currency for the leaderboard.
@splee
splee / example.py
Created May 30, 2011 16:13
An example for the #gevent IRC channel
from gevent.queue import Queue
from gevent.event import Event
import gevent
import logging
# The event which brings everything to a halt
stop_event = Event()
# set up logging
logging.basicConfig(filename='expire.log', level=logging.DEBUG)
# In-memory Cassandra-ish thingy... useful for unit tests. Maybe useful for other
# stuff too? No support for SuperColumns, but that should be easy enough to add.
import bisect
import copy
from cassandra.ttypes import NotFoundException, Column, ColumnPath, ColumnOrSuperColumn
class SSTable(object):