This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CHECKED_STATIC_CAST_H_ | |
#define CHECKED_STATIC_CAST_H_ | |
#include <limits> | |
namespace checked_static_cast { | |
template<typename T, typename U, bool S> | |
struct StaticCast { }; | |
template<typename T, typename U> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# usage: | |
# with Pid("/var/run/potato.pid"): | |
# do_stuff() | |
def is_running(pid): | |
try: | |
os.kill(pid, 0) | |
except OSError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cloudmanager | |
import metachains_dtc | |
import settings | |
coin = metachains_dtc.Datacoin( | |
settings.DATACOIN_URL, | |
settings.DATACOIN_USERNAME, | |
settings.DATACOIN_PASSWORD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PluginBase | |
def self.inherited child | |
# Register 'child' in PluginList | |
puts "ooh sweet #{child} o' mine" | |
end | |
end | |
class X < PluginBase | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function safe_component($component) { | |
return !!preg_match("/^([a-zA-Z0-9_]+\.?)+$/", $component); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pinger (threading.Thread): | |
def __init__(self, reporter): | |
self.reporter = reporter | |
threading.Thread.__init__() | |
daemon = True | |
def run (self): | |
while True: | |
self.reporter.ping() | |
time.sleep(60) |