Skip to content

Instantly share code, notes, and snippets.

@zbskii
zbskii / lockfile.py
Created January 22, 2014 01:10
Lockfile lib
import os
import fcntl
from contextlib import contextmanager
@contextmanager
def file_lock(lock_file):
if os.path.exists(lock_file):
raise RuntimeError("Lockfile exists: %s" % lock_file)
else:
function bal(){
$serversNew = array();
$servers = array("host1", "host2", "host3", "host4");
$query = "give me all the";
$numServers = count($servers);
while($numServers > 0) {
$key = hexdec(substr(md5($numServers . '+' . $query),0,4))%($numServers);
class apps::tomcat7::tomcat7flow inherits apps::tomcat7::serverconf {
$ip_address = '127.0.0.1'
File['/var/lib/tomcat7/conf/server.xml']{
ensure => 'present',
content => template('apps/flowservice/server7.erb'),
notify => Service['tomcat7'],
}
}
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
[{"code":"ZNZ","city":"ZANZIBAR","country":"TANZANIA","lat":"-6.13","lon":"39.31"},{"code":"TYO","city":"TOKYO","country":"JAPAN","lat":"35.68","lon":"139.76"},{"code":"AKL","city":"AUCKLAND","country":"NEW ZEALAND","lat":"-36.85","lon":"174.78"},{"code":"BKK","city":"BANGKOK","country":"THAILAND","lat":"13.75","lon":"100.48"},{"code":"DEL","city":"DELHI","country":"INDIA","lat":"29.01","lon":"77.38"}, {"code":"SIN","city":"SINGAPORE","country":"SINGAPOR","lat":"1.36","lon":"103.75"},{"code":"BSB","city":"BRASILIA","country":"BRAZIL","lat":"-15.67","lon":"-47.43"},{"code":"RIO","city":"RIO DE JANEIRO","country":"BRAZIL","lat":"-22.90","lon":"-43.24"},{"code":"YTO","city":"TORONTO","country":"CANADA","lat":"43.64","lon":"-79.40"},{"code":"IPC","city":"EASTER ISLAND","country":"CHILE","lat":"-27.11","lon":"-109.36"},{"code":"SEA","city":"SEATTLE","country":"USA","lat":"47.61","lon":"-122.33"}];
@zbskii
zbskii / log4j.xml
Created October 1, 2012 21:09 — forked from lusis/log4j.xml
Ruby logstash cli application - allows searching historical data in ElasticSearch or live tailing from AMQP topic exchange
<!-- the env variables are controlled by Chef and passed in via -D on the java command-line -->
<!-- This is using the appender here: https://github.com/t0xa/gelfj -->
<appender name="graylog2" class="org.graylog2.log.GelfAppender">
<param name="graylogHost" value="${graylog.server}"/>
<param name="originHost" value="${graylog.origin}"/>
<param name="extractStacktrace" value="true"/>
<param name="addExtendedInformation" value="true"/>
<!-- The _web part is because a given app has multiple components -->
<!-- This app might have a _web as well as an _batch component -->
<param name="facility" value="${graylog.facility}_web"/>
function encode64($input, $count)
{
$output = '';
$i = 0;
do {
$value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f]; // % 64
if ($i < $count)
$value |= ord($input[$i]) << 8; // ord * 2^8
$output .= $this->itoa64[($value >> 6) & 0x3f]; // (ord div 64) % 64
@zbskii
zbskii / gist:3699880
Created September 11, 2012 17:08
Ruby allocations
require 'rubygems'
require 'ruby-prof'
RubyProf.measure_mode = RubyProf::ALLOCATIONS
RubyProf.start
1_000_000.times{ Array.new(10) }
result = RubyProf.stop
# Print a flat profile to text
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
1.9.2p320 :006 > x
=> ["𠜎"]
1.9.2p320 :007 > x.to_json
=> "[\"\\u070e\"]"
1.9.2p320 :008 > JSON.dump x
=> "[\"𠜎\"]"
Enclosing class/module 'mDigest' for class MD5 not known
Enclosing class/module 'mDigest' for class RMD160 not known
Enclosing class/module 'mDigest' for class SHA1 not known
Enclosing class/module "cASN1ObjectId" for alias short_name sn not known
Enclosing class/module "cASN1ObjectId" for alias long_name ln not known