Skip to content

Instantly share code, notes, and snippets.

@rcrowley
rcrowley / repl.php
Created August 5, 2009 00:38
php-repl
<?php
while (true) {
fprintf(STDERR, '/*php*/ ');
$filename = tempnam('', 'php-repl-');
file_put_contents($filename, array("<?php\n", fgets(STDIN)));
require_once $filename;
unlink($filename);
}
unlink($argv[1]);
$ii = count(explode("/", $argv[1])) - 2;
for ($i = 0; $i < $ii; ++$i) {
if (!@rmdir($argv[1] = dirname($argv[1]))) { break; }
}
# Fake RubyGems
# http://gist.github.com/223216 is an expansion of Chris'
# http://gist.github.com/157899 that allows Rails to work properly
module Rip
module Commands
FAKE_RUBYGEMS = <<EOM
require 'thread'
def gem(name, *args)
raise LoadError if name =~ /adapter$/
raise Gem::LoadError unless name =~ /^rails|rack$/
#!/bin/sh
sysctl -w kern.maxproc=2048
sysctl -w kern.maxprocperuid=1024
echo kern.maxproc=2048 >>/etc/sysctl.conf
echo kern.maxprocperuid=1024 >>/etc/sysctl.conf
echo limit maxproc 1024 2048 >>/etc/launchd.conf
@rcrowley
rcrowley / gist:271494
Created January 7, 2010 19:40
strtotime() gotcha
$ # Bad
$
$ php -r 'echo date("r", strtotime("-1 month", strtotime("2009-12-31"))), "\n";'
Tue, 01 Dec 2009 00:00:00 +0000
$
$ php -r 'echo date("r", strtotime("-1 month", strtotime("2009-11-30"))), "\n";'
Fri, 30 Oct 2009 00:00:00 +0000
$
$
$
/* Print the pointer size as seen by gcc. */
#include <stdio.h>
int main(int argc, char **argv) {
printf("%d\n", 8 * sizeof(void *));
return 0;
}
@rcrowley
rcrowley / gist:282493
Created January 21, 2010 01:11
WTF is that error code?
$ python -c 'import errno, sys; print(errno.errorcode[int(sys.argv[1])])' 17
EEXIST
$ python -c 'import errno, sys; print(errno.errorcode[int(sys.argv[1])])' 2
ENOENT
$
(master) root@devbox:~/play/chefplay# pwd
/root/play/chefplay
(master) root@devbox:~/play/chefplay# cat solo.rb
file_cache_path "/root/play/chefplay/file-cache"
cookbook_path "/root/play/chefplay/file-cache/cookbooks"
(master) root@devbox:~/play/chefplay# ls -l file-cache/cookbooks/
total 0
lrwxrwxrwx 1 root root 32 Jan 24 00:05 build-essential -> ../all-cookbooks/build-essential
lrwxrwxrwx 1 root root 22 Jan 24 05:17 rails -> ../all-cookbooks/rails
lrwxrwxrwx 1 root root 21 Jan 24 05:04 ruby -> ../all-cookbooks/ruby
@rcrowley
rcrowley / gist:320863
Created March 3, 2010 18:57
RubyGems 1.3.5 to 1.3.6 regression
$ /usr/bin/gem --version
1.3.5
$ /usr/bin/gem unpack .rip/rip-packages/clint-683c264115582cf6d2be53b01a12f0ed.gem --target=/home/rcrowley/.rip/rip-packages
Unpacked gem: '/home/rcrowley/.rip/rip-packages/clint-683c264115582cf6d2be53b01a12f0ed'
$
$ gem --version
1.3.6
$ gem unpack .rip/rip-packages/clint-683c264115582cf6d2be53b01a12f0ed.gem --target=/home/rcrowley/.rip/rip-packages
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/ruby-1.8.7/lib/ruby/gems/1.8 directory.
@rcrowley
rcrowley / config.ru
Created March 23, 2010 22:59
Fresher reloads loaded code files that have changed before each request
require 'fresher'
use Fresher
require 'myapp'
run MyApp