Skip to content

Instantly share code, notes, and snippets.

View emberian's full-sized avatar

emberian

View GitHub Profile
Hub.listen('irc/*', function(Event) {
if (Event.payload.sender = "Octayn") {
Event.payload.message = "<Censored for stupidty>"
}
Event.next() // The new payload is sent
})
Hub.listen('irc/*', function(Event) {
if (ignore_list.indexOf(Event.payload.sender) !== -1) {
Event.next()
Hub.listen('irc/*', function(Event) {
Event.next()
Event.next( create_new_event_to_send_to_children_in_tree() )
})
/* Do `fn` `times` times every `timeout` milliseconds. Add in your own error condition handling */
function retry(fn, times, timeout) {
if (typeof fn !== 'function') {
return
}
times || (times = 3) // Third time's the charm
timeout || (timeout = 1000)
var trys = 0
function do_retry() {
if (times++ < tries) {
@emberian
emberian / BXscGvpi
Created March 25, 2012 20:25 — forked from anonymous/BXscGvpi
a guest on Mar 25th, 2012 - -.- ?
function lastElement(array) {
if (array.length > 0)
return array[array.length - 1];
else
return null;
}
show(lastElement([1, 2, null]));
@emberian
emberian / aEFVTHdB
Created April 7, 2012 16:31 — forked from anonymous/aEFVTHdB
a guest on Apr 7th, 2012 - SVetter
$.ajax({
type: "POST",
url: "meta-parse.php",
data: $('input.#url').serialize(),
success: function(data) {
var json = $.parseJSON(data);
var images = json.images.split(',');
$('#url_preview').html("<div id='message'></div>");
$('#url_preview').toggle();
$('#add_process_board_picker').toggle();
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct
{ unsigned long length
; char *data
;
} String;
{% block css %}
{{ super() }}
<link rel="stylesheet" href="css/index.css">
{% endblock %}
<h1>Fly them high</h1>
<form>
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password"
name="password">
@emberian
emberian / gist:2802595
Created May 27, 2012 07:25
Confusing psycopg2 behavior
(python)[kb1pkl@Ulysses:hacking/python]$ python (05-27 03:21)
Python 2.7.3 (default, Apr 30 2012, 21:18:11)
[GCC 4.7.0 20120416 (Red Hat 4.7.0-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2 as pg
>>> conn = pg.connect('user=flyl dbname=flyl')
>>> c = conn.cursor()
>>> c.execute('INSERT INTO files (name, owner) VALUES (%s, %s) RETURNING id;', ("foo", "bar"))
>>> c.fetchall()
[(15,)]
@emberian
emberian / modified one
Created May 31, 2012 21:12
Timing results
[kb1pkl@Ulysses:src/Python-3.2.3]$ time ./python /tmp/one.py (05-31 16:46)
./python /tmp/one.py 10.62s user 0.02s system 97% cpu 10.955 total
[kb1pkl@Ulysses:src/Python-3.2.3]$ time ./python /tmp/one.py (05-31 16:47)
./python /tmp/one.py 10.32s user 0.01s system 97% cpu 10.627 total
[kb1pkl@Ulysses:src/Python-3.2.3]$ time ./python /tmp/one.py (05-31 16:47)
./python /tmp/one.py 10.47s user 0.01s system 97% cpu 10.781 total
[kb1pkl@Ulysses:src/Python-3.2.3]$ time ./python /tmp/one.py (05-31 16:47)
./python /tmp/one.py 10.72s user 0.01s system 95% cpu 11.212 total
[kb1pkl@Ulysses:src/Python-3.2.3]$ time ./python /tmp/one.py (05-31 16:47)
./python /tmp/one.py 10.82s user 0.01s system 97% cpu 11.138 total
>>> def generate(startdate, recipients, daycount, message):
... last_date = startdate
... mail = email.message_from_string(message)
... msg_lib = []
... for i in range(0, daycount):
... for recep in range(len(recipients)):
... mail['date'] = email.utils.formatdate(time.mktime(last_date.utctimetuple()))
... msg_lib.append(mail)
... last_date = last_date + datetime.timedelta(days=1)
... return msg_lib