Skip to content

Instantly share code, notes, and snippets.

@timothyekl
timothyekl / list2sql.rb
Created July 11, 2011 15:11
Read from stdin, converting to MySQL 'values' tuples
while line = $stdin.gets
puts "(" + line.split.map {|i| "'#{i}'"}.join(',') + "),"
end
@timothyekl
timothyekl / smart_split.rb
Created July 14, 2011 13:52
Ruby: split string, respecting double quotes
class String
def smart_split
sa = self.split(/"/).collect { |x| x.strip }
return (1..sa.length).zip(sa).collect { |i,x| (i&1).zero? ? x : x.split }.flatten
end
end
@timothyekl
timothyekl / recompile.rb
Created July 26, 2011 20:33
Watch a directory recursively, recompiling .tex files on changes
require 'rb-inotify'
notifier = INotify::Notifier.new
notifier.watch('.', :modify, :recursive) do |event|
if event.name.end_with? ".tex"
puts "#{`date`.chomp}: Modified #{event.name}; recompiling..."
`pdflatex -interaction batchmode -output-directory #{File.dirname(event.absolute_name)} #{event.absolute_name} > /dev/null 2>&1`
end
end
@timothyekl
timothyekl / recompile.py
Created July 27, 2011 15:04
Recompile .tex files based on inotify from Python
import pyinotify
import os
import sys
class Handler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
if event.name.endswith('.tex'):
print "Recompiling " + event.name + "..."
os.popen('pdflatex ' + event.name).read()
@timothyekl
timothyekl / gist:1137985
Created August 10, 2011 19:53
Singleton tuplization of a set wrapper class's elements
class FooIterator:
def __init__(self, underlyingIter):
self.underlying = underlyingIter
def __iter__(self):
return self
def next(self):
try:
return (self.underlying.next(),)
@timothyekl
timothyekl / gist:1217887
Created September 14, 2011 21:44
Cross-platform: recompile LaTeX documents using Ruby, Guard
# Tested with Ruby 1.9
# Needs gem "guard" (https://github.com/guard/guard)
# Needs gem "guard-shell" (https://github.com/guard/guard-shell)
# Uses process "growlnotify" (http://growl.info/extras.php)
# Uses process "pdflatex" from standard TeXLive distribution
guard 'shell' do
watch(%r{(.+)\.tex}) do |m|
`growlnotify -m #{m[0]} Recompiling`
`pdflatex -interaction=batchmode #{m[0]} >/dev/null`
@timothyekl
timothyekl / config.yml
Created November 21, 2011 01:25
PneumatiCraft ChatSuite config
plugin:
default_locale: en
locales: [en]
# if allow_channels is false, your users will be unable to use any channel
# related commands, and as such the default channel will become their permanent
# chat place (it is recommended to set default_channel to global if you set this to false)
# note: a change to this setting will require a full /reload or server restart
allow_channels: true
allow_whispers: true
allow_afk: true
#import <stdio.h>
int main(int argc, char *argv[]) {
printf("Get things done!");
return 0;
}
@timothyekl
timothyekl / gist:5587371
Created May 15, 2013 21:05
rdar://13903643 - "NSCell does not implement methods declared in NSTextAttachmentCell protocol" NSTextAttachmentCell's documentation claims that NSCell implements all but three of its methods. This isn't the case.
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
SEL *selectors = malloc(10 * sizeof(SEL));
// The following selectors are taken from the NSTextAttachmentCell protocol reference.
// That document states that NSCell responds to all of its declared methods with three exceptions (noted below).
@timothyekl
timothyekl / keynote2pdf.scpt
Created May 28, 2013 14:33
Convert Keynote 5.3 documents to PDF
on run
display dialog "Drag keynote documents on me to convert to PDF."
end run
on open draggeditems
repeat with thisFile in draggeditems as list
tell application "Finder" to reveal item thisFile
set thisFile to thisFile as alias
tell application "Keynote" to open thisFile