Skip to content

Instantly share code, notes, and snippets.

View cvonkleist's full-sized avatar

Christian von Kleist cvonkleist

View GitHub Profile
class MyModel
attribute :complex_object_store
def complex_object=(object)
self.complex_object_store = Base64.encode64(Marshal.dump(object))
end
def complex_object
Marshal.load(Base64.decode64(self.complex_object_store))
end
#!/usr/bin/env ruby
ALPHABET = ['a'..'z', 'A'..'Z', '0'..'9'].collect { |range| range.to_a }.flatten
class Array; def random; self[rand(self.length)]; end; end
length = (ARGV.shift || 10).to_i
puts Array.new(length) { ALPHABET.random }.join
@cvonkleist
cvonkleist / categorizer.rb
Created January 20, 2011 16:37
a spec from categorizer_spec.rb
describe 'categorizer command-line stuff' do
it 'should write entity ids to case files' do
fake_suggestions = {
:jp2 => ['/foo/XX00000011.xml', '/bar/YY00000022.xml'],
:tiff => ['/bar/zz.xml', '/foo/abc.xml']
}
mock_jp2_output = mock('file')
mock_tiff_output = mock('file')
@cvonkleist
cvonkleist / cvk.zsh-theme
Created January 7, 2011 17:11
modification of jreese
# ripoff of jreese.zsh-theme
if [ "$(whoami)" = "root" ]; then NCOLOR="red"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
PROMPT='%m \
$(git_prompt_info)\
%(!.#.%%) '
#PROMPT='%{%{$fg[green]%}%m%{$reset_color%} \
#$(git_prompt_info)\
@cvonkleist
cvonkleist / irbrc.rb
Created January 7, 2011 17:04
easy way to preview html in a variable
# put this in ~/.irbrc
def h(html)
File.open('/tmp/irb.html', 'w') { |f| f.write html }
`chromium /tmp/irb.html`
end
Example:
% irb
@cvonkleist
cvonkleist / gist:704188
Created November 17, 2010 22:04
forking retarded web server
require 'socket'
listener = TCPServer.new(8888)
loop do
puts 'waiting for connection...'
sock = listener.accept
fork do
puts 'i am child'
filename = sock.gets.split[1]
begin
escape ^]]
startup_message off
defflow auto
defscrollback 5000
altscreen on
autodetach on
msgwait 3
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <openssl/evp.h>
// compile with: gcc -lssl find.c
<?php
require "inc/mysql.inc.php";
?>
<html>
<head><title>Oh, Those Admins!</title></head>
<body><center><h1>Oh, hi!</h1>
<?php
if (isset($_GET['password'])) {
$r = mysql_query("SELECT login FROM admins WHERE password = '" . md5($_GET['password'], true) . "'");
if (mysql_num_rows($r) < 1)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <openssl/evp.h>