Skip to content

Instantly share code, notes, and snippets.

View jbarciauskas's full-sized avatar

Joel Barciauskas jbarciauskas

View GitHub Profile
@jbarciauskas
jbarciauskas / crawler.py
Created February 1, 2011 18:44
Crawl urls loaded from a file and print the links found on them
#!/usr/bin/python
import sys
import urllib
from BeautifulSoup import BeautifulSoup, SoupStrainer
import re
filename = sys.argv[1]
with open(filename) as f:
import codecs
def unicode_safe_127(ss):
"""safely handle strings with hard ordinal values greater than 127
by escaping each value as appropriate"""
mys = ss
tos=[]
for i,s in enumerate(mys):
if ord(s)>127:
print codecs.unicode_escape_encode(mys)[0]
@jbarciauskas
jbarciauskas / gist:989746
Created May 24, 2011 21:29
unroot before making the repo dir
[sandboxuser@box42-107 blueprint]$ git diff
diff --git a/blueprint/git.py b/blueprint/git.py
index 39f7743..c6ea528 100644
--- a/blueprint/git.py
+++ b/blueprint/git.py
@@ -27,6 +27,7 @@ def init():
"""
dirname = repo()
try:
+ unroot()
@jbarciauskas
jbarciauskas / manage_ebs_raid.rb
Created June 12, 2011 03:00
Script to manage ebs raid volumes with logical names and timestamps
require 'rubygems'
require 'fog'
require 'ap'
require 'time'
def print_usage()
puts "Assumes all devices from sdc to sdz are available"
puts "Usage: volume attach [aws instance id] ['raid-name' tag value] ['snap-time' tag value]"
puts "Usage: volume detach ['raid-name' tag value] ['snap-time' tag value]"
puts "Usage: volume create ['raid-name' tag value] ['snap-time' tag value]"
@jbarciauskas
jbarciauskas / StatsD.php
Created July 5, 2011 16:25
PHP client for StatsD
<?php
/**
* Sends statistics to the stats daemon over UDP
*
**/
class StatsD {
/**
[~/src/logstash]> git diff
diff --git a/lib/logstash/agent.rb b/lib/logstash/agent.rb
index 750aba6..23fff2a 100644
--- a/lib/logstash/agent.rb
+++ b/lib/logstash/agent.rb
@@ -15,6 +15,8 @@ require "optparse"
require "thread"
require "uri"
+include_class Java::java.lang.Error
<?php
class BitArray {
//Sacrifice 2x the amount of memory, so we can use pack/unpack easily
const INT_SIZE = 4;
private $bitArray;
public function __construct($numberOfBits, $bitArray = null) {
$numberOfInts = $numberOfBits / self::INT_SIZE / 8; // PHP_INT_SIZE is in bytes
require_once("BitArray.php");
$test = new BitArray(128);
$test->setBit(12);
$test2 = new BitArray(128);
$test2->setBit(126);
$test3 = BitArray::orFn($test, $test2);
var_dump($test3);
var_dump($test);
var_dump($test2);
$test2 = new BitArray(60);
<?php
class BitArray {
//Sacrifice 2x the amount of memory, so we can use pack/unpack easily
const INT_SIZE = 4;
private $bitmapString;
public function __construct($numberOfBits = 64, $bitmapString = null) {
if($bitmapString!= null)
<?php
require_once("BitArray.php");
$test = new BitArray(128);
$test->setBit(12);
var_dump($test->toIntArray());
$test2 = new BitArray(128);
$test2->setBit(126);
var_dump($test2->toIntArray());
$test3 = BitArray::orFn($test, $test2);
var_dump($test3->toIntArray());