Skip to content

Instantly share code, notes, and snippets.

// Parallelizes delivery to multiple devices across a worker pool.
// Begin by initializing lists for the jobs and results we're expecting.
// Then, divide the device information across these jobs, and submit them.
// Finally, call ".get()" on each of the jobs to wait until they're done.
@SuppressWarnings("unchecked")
public void parallelizeDelivery() throws ExecutionException {
try {
HashMap[] jobs = new HashMap[numWorkers];
Future[] results = new Future[numWorkers];
for(int i=0; i < numWorkers; i++)
import java.util.Timer;
import java.util.TimerTask;
import java.lang.reflect.Method;
public class Abomination {
String callback;
public static void main(String args[]) {
new Abomination().setInterval("lol", 1000);
sudo gem install miso-java --source=http://gemcutter.org
sudo miso-java-configure
miso-java create puppyapp
cd puppyapp
miso-java scaffold Puppy name breed
#### Run the SQL command it spits out ####
script/build
import scala.util.Random
import scala.actors.Actor
import scala.actors.Actor._
import java.security.MessageDigest
class HaystackActor extends Actor {
val rand = new Random
val sha1 = MessageDigest.getInstance("SHA1")
// Generates the SHA1 hash of a byte array.
import scala.util.Random
import scala.actors.Actor
import scala.actors.Actor._
import java.security.MessageDigest
class HaystackActor extends Actor {
val rand = new Random
val sha1 = MessageDigest.getInstance("SHA1")
// Generates the SHA1 hash of a byte array.
require 'tokyocabinet'
require 'dm-core'
include TokyoCabinet
# Hacky overriding for destroy because the original method was constantly
# reporting a new record and failing to pass a valid query to the delete method.
module DataMapper
module Resource
def destroy
return false unless repository.delete({:model => model, :id => id})
=== Simplest Form
insight:~ cscotta$ irb
irb(main):001:0> require 'activesupport'
=> true
irb(main):002:0> RUBY_VERSION
=> "1.9.1"
irb(main):003:0> "3437 Coeur D\xD5Alene".encoding
=> #<Encoding:UTF-8>
irb(main):004:0> "3437 Coeur D\xD5Alene".valid_encoding?
# backup_db.rb
# Remotely back up and securely download a copy of a MySQL database.
# Can be used in conjunction with cron to run nightly with a crontab like this:
# 0 0 * * * ruby /home/user/scripts/backup_db.rb
# Written by C. Scott Andreas (http://twitter.com/cscotta)
# No warranties, use entirely at your own risk. The author assumes no liability
# for any consequences of this script, including data loss, security breaches, and service unavailability.
# Released under an MIT-style License. Use, modify, and distribute this script as you like.
<!-- To display the "Feedback" widget on the right rather than the left,
add these styles below the code provided by Get Satisfaction.
Tested in IE6, IE7, Firefox 2, Firefox 3, and Safari 3.
See it in action at http://www.sunagocommunity.org/
Note: You'll need to download the modified background image from
http://sunagocommunity.org/images/feedback-mod.png and place it in your
/images/ folder (or edit the location below). Please serve this image
yourself rather than pulling it from the Sunago app server kthx.

Redirecting smart and dumb mobile browsers in Interface ERB templates
-—————————————————————————————————

In the page you’d like to redirect (or _header.html.erb) -

<%= mobile_redirect(‘http://www.google.com’, ‘http://www.microsoft.com’) %>

The first argument is the address for smart mobile devices defined in the smart_list array (see mobile_redirect method).

The second argument is the address for dumb mobile devices.