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 Polynomial | |
def initialize(coeffs) | |
raise ArgumentError.new("Need at least 2 coefficients.") if coeffs.size < 2 | |
@coeffs = coeffs | |
end | |
def to_s | |
output = [] | |
coeffs = @coeffs.dup |
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
(defun haml-ify () | |
"run html2haml on current buffer" | |
(interactive) | |
(setf filename buffer-file-name) | |
(setf newfilename (concat | |
(car (split-string filename "\\.")) ".html.haml")) | |
(save-buffer) | |
(shell-command (concat | |
"html2haml " filename " > " newfilename)) | |
(kill-buffer (current-buffer)) |
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 python | |
# (c) 2010 Phil Hofmann <[email protected]> | |
import os | |
from gimpfu import * | |
def batch_make_textures(input_pattern, output_path, output_prefix, size): | |
if not os.path.exists(output_path): | |
os.makedirs(output_path) | |
num_files, file_names = pdb.file_glob(input_pattern, 1) |
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
# monkey patch I18n to log used/missing translations | |
I18n.module_eval do | |
class << self | |
def my_logger | |
filename = File.join(RAILS_ROOT, %w(log translations.log)) | |
@my_logger ||= Logger.new(File.open(filename, 'a')) | |
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
# coll = Product.find_all_by_kind('material') + | |
# Product.find_all_by_kind('materialgroup') + | |
# Product.find_all_by_kind('pricegroup') + | |
# Product.find_all_by_kind('component') | |
# mass_translate(coll, [:name, :description], :en, :de) | |
# mass_translate(coll, [:name, :description], :de, [:en, :fr]) { |v, l| "#{v} (#{l})" } | |
# | |
# coll = Product.find_all_by_kind('product') | |
# mass_translate(coll, :name, :de, [:en, :fr]) | |
# |
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
# control mplayer remotely via rack | |
# | |
# load & append files (mp3, ogg, etc) & lists (m3u) | |
# http://localhost:3000/mplayer/loadfile+http://www.archive.org/download/af002/03_Swiss_Jazz.mp3 | |
# http://localhost:3000/mplayer/loadlist+http://www.archive.org/stream/af002 | |
# | |
# playback | |
# http://localhost:3000/mplayer/pause | |
# http://localhost:3000/mplayer/stop | |
# |
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 | |
# | |
# synopsis | |
# | |
# ruby merge_locales.rb config/locales translations.yml | |
require 'yaml' | |
require 'rubygems' | |
require 'highline/import' |
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
# see https://github.com/thomasjbradley/signature-pad for more details | |
instructions = JSON.load(data).map { |h| "line #{h['mx']},#{h['my']} #{h['lx']},#{h['ly']}" } * ' ' | |
system "convert -size 198x55 xc:transparent -stroke blue -draw '#{instructions}' signature.png" |
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 | |
# returns isbn10 if the given string represents a isbn13 | |
# returns the given string otherwise | |
def isbn13to10(line) | |
isbn13 = line.tr_s('- ', '') | |
return line unless isbn13.match(/\d{13}/) | |
isbn10 = isbn13[3,9] | |
checksum = 0 |
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 | |
require 'json' | |
require 'csv' | |
CSV do |csv| | |
data = JSON.parse(ARGF.read) | |
csv << data.first.keys.sort | |
data.each do |line| | |
csv << line.to_a.sort_by { |a| a.first }.map { |a| a.last } |
OlderNewer