Skip to content

Instantly share code, notes, and snippets.

View threez's full-sized avatar

threez

  • IONOS SE
  • Karlsruhe, Germany
View GitHub Profile
@threez
threez / psdb.rb
Created November 5, 2012 22:02
This is a small journaling multi process aware database for counting choises
require "fileutils"
# === PSDB Packed Stats Database
#
# This is a small journaling multi process aware database for counting choises.
#
# === Authors
# * dpree
# * threez
class PSDB
@threez
threez / fstab.rb
Created June 3, 2013 21:11
Ruby fstab ffi implementation for unix (mac os x / bsd)
require "ffi"
module Mount
class Fstab < FFI::Struct
layout :fs_spec, :string, # block special device name
:fs_file, :string, # file system path prefix
:fs_vfstype, :string, # File system type, ufs, nfs
:fs_mntops, :string, # Mount options ala -o
:fs_type, :string, # FSTAB_* from fs_mntops
:fs_freq, :int, # dump frequency, in days
@threez
threez / client.rb
Created July 24, 2013 06:33
Show that localhost can resolve to ::1 on MacOSX systems. Proven, if the client doesn't raise an error.
require 'drb/drb'
p DRb.start_service("druby://localhost:0")
server = DRbObject.new_with_uri("druby://::1:5000")
p server
p server.foo
@threez
threez / exim.rb
Last active December 20, 2015 16:09
Simple rspec prototype on how to test exim with rspec
require 'spec_helper'
describe 'Exim Config' do
let!(:exim) { exim_server(config) }
context 'simple config' do
let!(:relay) { mail_server(:y) }
let(:config) { exim_config(:simple) }
let(:mail_x) { mail_fixture(:mail_x) }
@threez
threez / mp3converter.rb
Created August 18, 2013 19:07
A simple script to convert m4a files into mp3 out of the itunes library. Best used in conjunction with the 'request itunes titles' automator task.
#!/usr/bin/env ruby
require 'open3'
require 'fileutils'
USER = 'XXX
CMD = '/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog'
MUSIC_LOCATION = "/Users/#{USER}/Music/iTunes/iTunes Music/"
TARGET_DIR = "/Users/#{USER}/Musik MP3"
# start cocoa dialog for progress bar
@threez
threez / pipe-rpc.rb
Created September 6, 2013 14:11
Simple RPC over a unix PIPE
class Message < Struct.new(:type, :payload)
REQUEST = ?<.freeze
RESPONSE = ?>.freeze
HEADER = 'NA'.freeze
CODER = Marshal
def self.request(payload)
new(REQUEST, payload)
end
@threez
threez / node-http-parser.js
Created January 23, 2014 07:42
In this example I played with the internal node http parser. This might be useful to folks that have to parse HTTP manually. For more info look at: https://github.com/joyent/node/blob/master/lib/_http_client.js
var HTTPParser = process.binding('http_parser').HTTPParser;
var parser = require("http").parsers.alloc();
parser.reinitialize(HTTPParser.RESPONSE);
parser.onBody = function(body) {
console.log(body.toString());
}
parser.onIncoming = function(response) {
console.log(response.headers);
console.log(response.statusCode);
@threez
threez / update_keystore_ldap.sh
Created March 3, 2014 10:20
Extract and update a ldap certificate in a java keystore (jenkins)
#!/bin/bash
LDAP_SERVER=example.com:636
ALIAS=LDAP_SERVER
KEYSTORE=/usr/lib/jvm/java-1.6.0-openjdk-amd64/jre/lib/security/cacerts
PASSWD=changeit
# grep the certificate
echo -n | openssl s_client -connect $LDAP_SERVER | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ldaps.crt
@threez
threez / dolight.js
Created April 19, 2014 18:11
Use ban to turn off/on the light if the door was opened
#!/usr/bin/env node
var WebSocketClient = require('websocket').client,
client = new WebSocketClient(),
url = 'ws://localhost:8080/',
light = '11011C';
function handleMessage(connection, data) {
var now = new Date();
// door was opened turn on the light
if (data['door-opened']) {
@threez
threez / mini-sqlite3.rb
Last active August 29, 2015 14:16
minimal sqlite3 driver
#!/usb/bin/env ruby
require 'fiddle'
require 'fiddle/import'
require 'pp'
module Sqlite3
SQLITE_OK = 0
module Driver
extend Fiddle::Importer