Skip to content

Instantly share code, notes, and snippets.

View cjhanks's full-sized avatar
🔥

zeekoni cjhanks

🔥
View GitHub Profile
#!/bin/bash
set -e
function test_funx {
r=0
((r++))
}
test_funx &
wait
@cjhanks
cjhanks / ping.py
Last active December 10, 2015 02:58 — forked from anonymous/ping.py
#!/usr/bin/env python
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
@cjhanks
cjhanks / gist:4489579
Last active December 10, 2015 20:38
Key checking
exclusion_set = set(('input', 'output')) - set(data_i)
{>
(> if exclusion_set:
raise RuntimeError('missing keys: %s' % str(exclusion_set))
@cjhanks
cjhanks / gist:4543272
Created January 15, 2013 23:47
Key checking
['app_name', 'method', 'type'].forEach ( function (item) {
if (!req.headers.hasOwnProperty(item)) {
throw {
etype : 'USER'
,ecode : 406
,source : 'HTTP LOCAL ROUTE'
,info : 'MISSING ITEM [' + item + ']'
}
}
@cjhanks
cjhanks / pipe.sh
Last active December 14, 2015 07:39
Showing atomic consistency of Unix PIPES in BASH.
#!/bin/bash
set -e
pipe_name="test_pipe"
# --------------------------------------------------------------------------- #
@cjhanks
cjhanks / pb2json.py
Created February 28, 2013 23:51
Protobuf --> Json and back
"""
:module pbf2json:
--------------------------------------------------------------------------------
License: Public Domain with no guarantees made
Date: 12/28/2012
http://cjhanks.name
--------------------------------------------------------------------------------
@cjhanks
cjhanks / test.js
Created March 19, 2013 22:53
Windows Server Test for OS module
var os = require ('os');
for (var i in os) {
console . log ('-------------------------------------------------------------------');
console . log (i);
console . log ((typeof os[i] === 'function') ? os[i]() : os[i]);
}
@cjhanks
cjhanks / jsloop.js
Created March 20, 2013 19:11
JS loop
Slot.prototype.poll = function () {
/* This polls infinitely for new work in the queue and if they become
* available properly routes the input into execution.
*
* Note that is very important to be careful to call semantics in this
* function to prevent stack overflow.
*/
var self = this;
self['swf'].pollForActivityTask(self['aws_opts'], function (err, res) {
@cjhanks
cjhanks / bootstrap.sh
Last active December 15, 2015 16:19
Basic Uploader using UDT for a quick upload need
#!/bin/bash
set -e
wget http://downloads.sourceforge.net/project/udt/udt/4.11/udt.sdk.4.11.tar.gz
tar xzvf udt.sdk.4.11.tar.gz
pushd udt4
make
@cjhanks
cjhanks / metajson.py
Created April 2, 2013 00:19
Allows a dictionary to act as an object and be serializable to JSON. Used for making JSON object behave like python objects.
import json
class MetaJson(dict):
"""
Allows a dictionary to act as an object and be serializable to JSON. Used
for making JSON object behave like python objects.
"""
def __init__(self, d = dict()):
dict.__init__(self,
{k: MetaJson(v) if isinstance(v, dict) else v for (k, v) in d.items()}