Skip to content

Instantly share code, notes, and snippets.

/* Custom YouTube Player Stylesheet for Firefox
by C. Scott Andreas (http://www.paradoxica.net)
Sept. 6, 2008. Creative Commons + Attribution License.
How do I use it?
--------------------------------------------------------
(1) Download and install the Stylish add-on for Firefox:
https://addons.mozilla.org/en-US/firefox/addon/2108
(2) Browse to a YouTube clip (on YouTube, not embedded)
/* Custom YouTube Player Stylesheet for Firefox ---------
by C. Scott Andreas (http://www.paradoxica.net)
Sept. 6, 2008. Creative Commons + Attribution License.
How to Use:
(1) Download and install the Stylish add-on for Firefox at
https://addons.mozilla.org/en-US/firefox/addon/2108
(2) Browse to a YouTube clip (on YouTube, not embedded)
such as http://www.youtube.com/watch?v=AcpJMBBUvys
# Basic regex + Ruby method to strip textile formatting.
# Handles all test cases at http://hobix.com/textile/ down to "Phrase Attributes."
def strip_textile(text)
text.gsub(/\b[_+^*~@%\-]{1,2}|[_+^*~@%\-]{1,2}\b|\b\?\?|\?\?\b|h\d\.\s|bq.\s|fn\d\.\s|\D\{.*\}\.\s?|\{.*\}\.\s?|\%\{.*\}|\D\(.*\)\.\s?|\{%.*\%\}\s|<.*?>/, "")
end

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.

<!-- 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.
# 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.
=== 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?
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})
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.