Skip to content

Instantly share code, notes, and snippets.

View tbarbugli's full-sized avatar

Tommaso Barbugli tbarbugli

View GitHub Profile
@tbarbugli
tbarbugli / reset.sql
Created May 1, 2013 13:10
reset all sequences on a postgres db
SELECT 'SELECT SETVAL(' ||quote_literal(S.relname)|| ', MAX(' ||quote_ident(C.attname)|| ') ) FROM ' ||quote_ident(T.relname)|| ';'
FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C
WHERE S.relkind = 'S'
AND S.oid = D.objid
AND D.refobjid = T.oid
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
ORDER BY S.relname;
import collections
import json
import redis
import threading
from tornado import gen
from tornado import ioloop
from tornado import web
from tornado.options import define
from tornado.options import options
import tornadoredis
class A(object):
def __init__(self):
super(A, self).__init__()
print 'class A'
class B(object):
def __init__(self):
super(B, self).__init__()
print 'class B'
===================
Collector (v 3.9.0)
===================
Status date: 2013-09-10 13:11:06 (10s ago)
Pid: 26192
Platform: Linux-3.2.0-37-virtual-x86_64-with-Ubuntu-12.04-precise
Python Version: 2.7.3
Logs: <stderr>, /var/log/datadog/collector.log, syslog:/dev/log
results = []
with ParallelQuery() as p:
for feed_chunk in chunks(feed_ids, 500):
results.append(model_manager.filter(feed_id__in=feed_chunk).order_by('-activity_id')[:3600])
feed_id | activity_id | actor | object | group | target | time
--------------+----------------------------+--------+-----------+--------+--------+--------------------------
feed:flat:13 | 13714123640000258443592003 | 876882 | 258443592 | 1 | 831803 | 2013-06-16 21:52:44+0000
feed:flat:13 | 13715879420000258938996003 | 255741 | 258938996 | 1 | 928068 | 2013-06-18 22:39:02+0000
feed:flat:13 | 13763288090000271471001003 | 186818 | 271471001 | 2 | -1 | 2013-08-12 19:33:29+0000
feed:flat:13 | 13769369290000272923490003 | 186818 | 272923490 | 1 | -1 | 2013-08-19 20:28:49+0000
feed:flat:13 | 13771839640000273566662003 | 186818 | 273566662 | 3 | -1 | 2013-08-22 17:06:04+0000
feed:flat:13 | 13771843770000273567924003 | 186818 | 273567924 | 2 | -1 | 2013-08-22 17:12:57+0000
feed:flat:13 | 13776966170000274963671003 | 186818 | 274963671 | 2 | -1 | 2013-08-28 15:30:17+0000
feed:flat:13 | 13776970820000274965647003 | 186818 | 27496564
<script>
alert()
</script>
$digest = hash_hmac('sha1', $feed_id, sha1($key, true), true);;
return trim(strtr(base64_encode($value), '+/', '-_'), '=');
@tbarbugli
tbarbugli / activity_enrich.php
Last active August 29, 2015 14:07
activity_enrich
<?php
function get_users($ids){
// queries the db and returns an assoc array eg. array(1=>user1,...)
return array(
'1'=> 'tommaso',
'2'=> 'mike',
'3'=> 'thierry',
);
@tbarbugli
tbarbugli / autoload.php
Created October 8, 2014 07:17
autoload.php
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}