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
@ybakos
ybakos / translator.rb
Created March 14, 2010 00:33
Example of Translator logic
class Translator
def self.translate!(filenames)
writer = CodeWriter.new('hello codewriter I hope you are feeling fine')
filenames.each do |vm_filename|
puts "Translating #{vm_filename} ..."
parser = Parser.new(vm_filename)
while parser.has_more_commands? do
writer.begin!(asm_file_name_for(vm_filename))
parser.advance
# "Computer, use the template filename TPL_PUSH_CONSTANT and open a File with that
# filename. Pass that file to ERB (who will substitute locally bound variable
# values, if any, within the text of the file). Take the result of ERB's processing and
# write it to the asm file."
def write_push_constant(constant)
@asmfile.write(ERB.new(File.read(TPL_PUSH_CONSTANT)).result(binding))
end
# Example push_constant.erb
// push constant <%= constant %>
<div class="message global europe technology all">
<p>Message content here. Each message's html would be similar.
Each message in the list would be wrapped in the div tag.</p>
<p>This allows you to write a message only once, as well as choosing which
subscribers should see the message.</p>
<p>You would just need to edit the subscription names above. For example,
if you wanted this message to be displayed for both technology and europe
subscribers, the stuff between quotes would be "message technology
europe".</p>
</div>
def self.sync_or_create(email, remote_user_resource)
u = self.find_or_create_by_email(email)
u.fname = remote_user_resource.first_name
u.lname = remote_user_resource.last_name
u.password = remote_user_resource.password
u.password_confirmation = remote_user_resource.password
u.save!
return u
end
Processing UserSessionsController#create (for 127.0.0.1 at 2010-07-01 10:57:19) [POST]
Parameters: {"commit"=>"Log in", "user_session"=>{"password"=>"[FILTERED]", "email"=>"[email protected]"}, "action"=>"create", "authenticity_token"=>"+FdTnSeqIia9xEBtS4vYpD8pruHE5MKh6Uk+zVLIE/8=", "controller"=>"user_sessions"}
User Columns (1.6ms) SHOW FIELDS FROM `users`
User Load (0.5ms) SELECT * FROM `users` WHERE (LOWER(`users`.email) = '[email protected]') LIMIT 1
SQL (0.2ms) BEGIN
User Update (0.4ms) UPDATE `users` SET `failed_login_count` = 0, `updated_at` = '2010-07-01 16:57:19', `perishable_token` = '2tGSuzTbRRyZ0NMJ6LeY', `last_login_at` = '2010-07-01 16:50:58', `current_login_at` = '2010-07-01 16:57:19', `login_count` = 30, `last_request_at` = '2010-07-01 16:57:19' WHERE `id` = 1
SQL (0.6ms) COMMIT
Redirected to http://someapp.local/login
Processing UserSessionsController#create (for 127.0.0.1 at 2010-07-01 11:48:57) [POST]
Parameters: {"commit"=>"Log in", "user_session"=>{"password"=>"[FILTERED]", "email"=>"[email protected]"}, "action"=>"create", "authenticity_token"=>"+FdTnSeqIia9xEBtS4vYpD8pruHE5MKh6Uk+zVLIE/8=", "controller"=>"user_sessions"}
User Columns (10.6ms) SHOW FIELDS FROM `users`
# sync_or_create() called. before find_or_create_by_email
User Load (0.4ms) SELECT * FROM `users` WHERE (`users`.`email` = '[email protected]') LIMIT 1
# after find_or_create by email
# before save! ing
SQL (0.2ms) BEGIN
# BEFORE AR VALIDATION
User Load (0.4ms) SELECT `users`.id FROM `users` WHERE (`users`.`persistence_token` = BINARY 'fb62b793ac317670da4aac2a175467a0813d9d25c3b0f6803dbd855e068e08f6c6328614220be40f90d3d759c2862c3d83a33968d803e0d88ed303154d06a1d8' AND `users`.id <> 1) LIMIT 1
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "t123", automatically
# adds "Refs #123." to commit messages unless they mention "#123" already.
# Include "#noref" in the message to avoid this behavior for the current commit.
# The "#noref" will be stripped from the commit message.
#
# By Henrik Nyh <http://henrik.nyh.se> 2009-09-10 under the MIT License.
#
#
Rails CMS alternatives
======================
Note: project activity was checked on 11/26/09 for most of these projects, and the "last update" field has not been kept up to date since then.
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
package org.testgame
trait Named {
def name: String
}
trait Described {
def description: String
}
trait Item extends Named with Described {
@ybakos
ybakos / .profile
Created May 1, 2011 19:37 — forked from mconnell/.profile
My Sublime Text 2 settings.
alias sublime='open -a "Sublime Text 2"'