Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
hugopeixoto / inherited.rb
Created March 5, 2014 23:59
inheritance hooks
class PluginBase
def self.inherited child
# Register 'child' in PluginList
puts "ooh sweet #{child} o' mine"
end
end
class X < PluginBase
end
@hugopeixoto
hugopeixoto / worker.py
Created March 9, 2014 20:25
metachains_dtc worker
import cloudmanager
import metachains_dtc
import settings
coin = metachains_dtc.Datacoin(
settings.DATACOIN_URL,
settings.DATACOIN_USERNAME,
settings.DATACOIN_PASSWORD)
@hugopeixoto
hugopeixoto / btc.sh
Last active August 29, 2015 13:57
btc.sh
#!/bin/bash
btce_price() {
python -c 'import json; import sys; print json.load(sys.stdin)["markets"]["btce"]["price"]'
}
AMOUNT=${1:-1.0}
USD=$(curl -sf http://preev.com/pulse/source:btce/unit:btc,usd | btce_price)
EUR=$(curl -sf http://preev.com/pulse/source:btce/unit:btc,eur | btce_price)
@hugopeixoto
hugopeixoto / pid.py
Last active August 29, 2015 14:01
pidfile management
import os
# usage:
# with Pid("/var/run/potato.pid"):
# do_stuff()
def is_running(pid):
try:
os.kill(pid, 0)
except OSError:
@hugopeixoto
hugopeixoto / yaml_conf.py
Created May 18, 2014 13:06
Retrieves configuration from a directory containing yaml configuration files
def read_yaml_configuration_directory(directory):
config = {}
for root, _, filenames in os.walk(directory):
for fname in filenames:
if fname.endswith(".conf"):
with open(root + "/" + fname) as f:
config.update(yaml.safe_load(f))
return config
#!/usr/bin/env ruby
n = ARGV.shift.to_i
puts((n.times.map do |i|
" "*(n-1-i) + "*"*(1+2*i)
end + (n/2).times.map do
" "*(n/2) + "#"*(n-1+(n%2))
end).join("\n"))
#include <stdio.h>
#include <dirent.h>
int main(int argc, char* argv[]) {
int file_count = 0;
DIR * dirp;
struct dirent * entry;
dirp = opendir(argc == 2 ? argv[1] : "."); /* There should be error handling after this */
if (dirp == NULL) {
@hugopeixoto
hugopeixoto / upstart example
Created September 24, 2014 14:54
upstart example
# daemon-name - registration service
#
description "registration service"
start on (local-filesystems and runlevel [2345])
stop on runlevel [06]
setuid v11registration-runner
setgid v11registration-runner
#include <stdio.h>
struct fish_key_store {
void* data;
int (*getter) (void*, const char*, char*, size_t);
int (*setter) (void*, const char*, const char*);
};
struct fish_key_store fish_key_store_make (void* data, void* getter, void* setter) {
return (struct fish_key_store){
#!/bin/bash
curl --silent http://www.debian.org/international/l10n/po-debconf/pt |
grep 'href="http://i18n.debian.org/material/po/.*.po.gz">pt.po</a>' |
sed -e 's/.*name="\([^"]*\)".*href="\([^"]*\)".*/\1 \2/' |
while read line
do
a=( $line )
name="${a[0]}"
url="${a[1]}"