Skip to content

Instantly share code, notes, and snippets.

View tzuryby's full-sized avatar

Tzury Bar Yochay tzuryby

View GitHub Profile
@tzuryby
tzuryby / gist:279884
Created January 18, 2010 08:30
Paul Buchheit: Summarize your life in one word:
>>> sum([ord(c) for c in "your life"])
911
>>> import ctypes
>>> ctypes.c_uint32(911)
c_uint(911L)
@tzuryby
tzuryby / daemon.py
Created May 8, 2011 08:40
A generic python daemon class
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
@tzuryby
tzuryby / logger.py
Created December 14, 2011 02:34
python logger with colors
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'Tzury Bar Yochay'
__version__ = '0.1'
__license__ = 'GPLv3'
import logging
from logging import handlers
@tzuryby
tzuryby / defaultdict.lua
Created June 6, 2020 14:10
lua implementaiton of python's default dict
function defaultdict(callable)
local T = {}
setmetatable(T, {
__index = function(T, key)
local val = rawget(T, key)
if not val then
rawset(T, key, callable())
end
return rawget(T, key)
end
@tzuryby
tzuryby / random-ipv4.sh
Created April 3, 2020 05:46
random ipv4
while true; do
ipv4=$(dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -An -tu1 | sed -e 's/^ *//' | sed 's/ */./g')
echo $ipv4
done
@tzuryby
tzuryby / aggregate-cidr-addresses.pl
Created August 30, 2018 08:13 — forked from denji/README.md
Take a list of CIDR address blocks and combine them, for example, 192.168.0.0/24 and 192.168.1.0/24 gives 192.168.0.0/23. I usually use "list-iana-reserved-ranges | aggregate-cidr-addresses" to get a list of blocks to not report with firewall log processing. https://github.com/job/aggregate6
#!/usr/bin/perl
#
# aggregate-cidr-addresses - combine a list of CIDR address blocks
# Copyright (C) 2001,2007 Mark Suter <suter@zwitterion.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@tzuryby
tzuryby / gist:975588
Created May 16, 2011 23:27
Stream handlers with Tornado
class StreamHandler(AMSHandler):
@tornado.web.asynchronous
def get(self):
self.post()
@tornado.web.asynchronous
def post(self):
self.write("<pre>")
self.ioloop = tornado.ioloop.IOLoop.instance()
self.pipe = self.get_pipe()
@tzuryby
tzuryby / hash32.py
Created March 29, 2011 04:33
32bit hash function for python
hash32 = lambda value: hash(value) & 0xffffffff
@tzuryby
tzuryby / 0 - README.md
Created December 4, 2016 01:56 — forked from JamesMGreene/0 - README.md
A brief example of the latest idea for communicating with PhantomJS from the client-side.

A brief example of the latest idea for communicating with PhantomJS from the client-side.

This is the next revision of ideas discussed in a previous Gist:
    https://gist.github.com/JamesMGreene/3716654

This example demonstrates shimming in the new communication channels under discussion via existing methods (WebPage#onCallback and window.callPhantom).

The example does, however, take advantage of a yet-to-be-implemented EventEmitter API for core modules in the PhantomJS outer context. This API would add the following methods to core modules as appropriate:

  • on / addEventListener
<div id="share-buttons"></div>
<style type="text/css">
#share-buttons img {
width: 25px;
padding: 5px;
border: 0;
box-shadow: 0;
display: inline;