Skip to content

Instantly share code, notes, and snippets.

View ybakos's full-sized avatar
💭
the machine stops the machine stops the machine stops

Yong Joseph Bakos ybakos

💭
the machine stops the machine stops the machine stops
View GitHub Profile
dscl localhost -list /Local/Default/Hosts
svn remove log/*
svn propset svn:ignore "*.log" log/
svn remove tmp/*
svn propset svn:ignore "*" tmp/
#!/usr/bin/ruby
require 'yaml'
require 'cgi'
SVNLOOK = '/usr/bin/svnlook'
CURL = '/usr/bin/curl'
LOG_FILE = '/tmp/svn-hooks.log'
# Configuration
# Set your basecamp url, username, password and project id here.
Enter ".help" for instructions
sqlite> CREATE TABLE data (name STRING, address STRING, salary INTEGER);
sqlite> .mode csv
sqlite> .import out.csv data
sqlite> .quit
@ybakos
ybakos / New Ruby, Old Rails
Created February 11, 2010 17:21
undefined method length for Enumerable Enumerator
module ActionView
module Helpers
module TextHelper
def truncate(text, length = 30, truncate_string = "...")
if text.nil? then return end
l = length - truncate_string.chars.to_a.size
(text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
end
end
end
class Photo < ActiveRecord::Base
belongs_to :photographable, :polymorphic => true
has_attached_file :source,
:styles => { :normal => ['112x112^', :png] },
:default_style => :normal,
:path => ":rails_root/public/assets/:class/:attachment/:id/:style/:basename.:extension",
:url => "/assets/:class/:attachment/:id/:style/:basename.:extension"
acts_as_list :scope => :photographable
end
File.open(asm_filename, 'r') do |infile|
outfile = File.open(hack_filename, 'w') do |outfile|
assembler = Assembler.new(infile, outfile)
assembler.go!
end
end
// WARNING: my java is rusty, so this is conceptual only. [yjb]
import java.util.Hashtable;
public class SymbolTable {
HashTable symbols;
public SymbolTable() {
symbols = new Hashtable(100);
@ybakos
ybakos / translator.rb
Created March 13, 2010 23:42
Excerpt from translator.rb, showing students filename handling
#
# Begin driver script.
#
# Expects only one argument, the .vm filename or directory
def args_valid?
if ARGV.size == 1 && (File.extname(ARGV[0]) == '.vm' || File.directory?(ARGV[0]))
true
else
false
@ybakos
ybakos / parser.rb
Created March 13, 2010 23:46
Parser example: from lines in a file to a structured array
class Parser
# Gets ready to parse the input file
def initialize(filename)
generate_command_array(filename) #
@index = 0
end
# ...