| ⌘T | go to file |
| ⌘⌃P | go to project |
| ⌘R | go to methods |
| ⌃G | go to line |
| ⌘KB | toggle side bar |
| ⌘⇧P | command prompt |
| require "digest/md5" | |
| require "resque-retry" | |
| require "resque-loner" | |
| # | |
| # Statused Worker Example: | |
| # | |
| # class MyStatusedWorker < StatusedWorker | |
| # def self.job_identity_arguments(user_id, credit_card_number, attributes = {}) | |
| # [user_id] |
| require 'digest' | |
| # Get SHA256 Hash of a file | |
| puts Digest::SHA256.hexdigest File.read "data.dat" | |
| # Get MD5 Hash of a file | |
| puts Digest::MD5.hexdigest File.read "data.dat" | |
| # Get MD5 Hash of a string | |
| puts Digest::SHA256.hexdigest "Hello World" | |
| # Get SHA256 Hash of a string using update |
| # Tweaked from http://tomislavsantek.iz.hr/2011/03/moving-mysql-databases-to-ramdisk-in-ubuntu-linux | |
| # Log in as root | |
| # Mount ramdisk folder in RAM | |
| mkdir /tmp/ramdisk | |
| mount -t tmpfs -o size=128M tmpfs /tmp/ramdisk/ | |
| # Move MySQL data | |
| mv /var/lib/mysql /tmp/ramdisk/mysql | |
| ln -s /tmp/ramdisk/mysql/ /var/lib/mysql |
| #!/usr/bin/env ruby | |
| # Lean Architecture example in Ruby - with ContextAccessor | |
| # This example keeps interaction state in a "current context", represented | |
| # by a ContextAccessor module. This can be mixed in to any class that needs | |
| # access to the current context. It is implemented as a thread-local variable. | |
| module ContextAccessor | |
| def context | |
| Thread.current[:context] |
| #!/usr/bin/env ruby | |
| # Lean Architecture example in Ruby - without ContextAccessor | |
| # In this example, the context passes the needed roles into each method it | |
| # invokes, and so the roles have no reference back to the context. | |
| # Model class with no external dependenices. Includes a simple find method | |
| # to create and store instances given an id - for illustration purposes only. | |
| class Account | |
| attr_reader :account_id, :balance |
| # this uses upcoming dm-validations, it's not released yet | |
| class User | |
| include Virtus | |
| include DataMapper::Validations | |
| # basic info | |
| attribute :email, String | |
| attribute :password, String | |
| attribute :password_confirmation, String |
#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)
Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.
(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)
##Option 1: Using jQuery 1.7's $.Callbacks() feature:
| require 'sinatra' | |
| require 'redis' | |
| require 'json' | |
| require 'date' | |
| class String | |
| def &(str) | |
| result = '' | |
| result.force_encoding("BINARY") |
| /*! | |
| * jQuery multi-dependency pubsub v0.01 | |
| * Copyright 2011, Adam Laughlin | |
| * http://a-laughlin.com | |
| * Licensed under MIT & GPL version 2 | |
| * http://static.a-laughlin.com/mit_license.txt | |
| * http://static.a-laughlin.com/gpl_license.txt | |
| * | |
| * inspired by Addy Osmani's example at: | |
| * http://addyosmani.com/blog/jquery-1-7s-callbacks-feature-demystified/ |