Skip to content

Instantly share code, notes, and snippets.

UTF8_REGEXP = / \A (?: [\x00-\x7F] | [\xC2-\xDF] [\x80-\xBF] | [\xE1-\xEF] [\x80-\xBF]{2} |
[\xF1-\xF7] [\x80-\xBF]{3} | [\xF9-\xFB] [\x80-\xBF]{4} |
[\xFD-\xFD] [\x80-\xBF]{5} ) \Z /x
# Return true if string is valid UTF-8
def utf8?(string)
string.split(//u).all? { |c| c =~ UTF8_REGEXP}
end
#!/usr/bin/env ruby -wKU
require "osx/cocoa"
include OSX
require_framework "ScriptingBridge"
class NextPreviewPlayer < NSObject
def initialize
def foo(&block)
puts :a
yield
puts :c
end
foo { puts :b }
# >> a
# >> b
# >> c
require "rubygems"
require "rack/contrib/accept_format" # sudo gem install rack-rack-contrib (http://github.com/rack/rack-contrib/tree/master)
require "sinatra"
require "yaml"
require "json"
use Rack::AcceptFormat
get "/foo.*" do
@data = %w[foo bar baz]
#!/usr/bin/env ruby
require "osx/cocoa"
require "erb"
require "base64"
include OSX
def pict_bytes_for(artwork)
image_rep = artwork.data.representations.first
data = image_rep.PICTRepresentation
$ gdb --args bin/rbx -r irb/completion -S irb
GNU gdb 6.3.50-20050815 (Apple version gdb-908) (Tue Feb 19 15:23:53 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared libraries .... done
(gdb) run
#!/usr/bin/env ruby
def fix_trailing_space(file)
content = File.read(file)
content.gsub!(/[\t ]+$/, '')
File.open(file, "w") { |file| file.write(content) }
end
status = `git status`.split("\n")
files = status.map do |e|
{:count=>1365}
{:size=>1365}
{:size=>101}
/home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.4/lib/em-mongo/connection.rb:184:in `block in receive_data': Buffer Overflow: Failed to parse buffer (RuntimeError)
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.4/lib/em-mongo/connection.rb:174:in `each'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.4/lib/em-mongo/connection.rb:174:in `map'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.4/lib/em-mongo/connection.rb:174:in `receive_data'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from mongoimport.rb:12:in `<main>'
/home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/bson-1.0.1/lib/bson/bson_c.rb:8:in `serialize': key must not start with '$' (BSON::InvalidKeyName)
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/bson-1.0.1/lib/bson/bson_c.rb:8:in `serialize'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.6/lib/em-mongo/connection.rb:85:in `update'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/em-mongo-0.2.6/lib/em-mongo/collection.rb:35:in `update'
from mongoimport.rb:13:in `block in <main>'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /home/jptix/.rvm/gems/ruby-1.9.1-p378/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from mongoimport.rb:11:in `<main>'
{
"_id": {
"$oid": "4bf80fb7b4522670e8682ae8"
},
"followers": {
"å": 1,
":/": 1,
":p": 1,
"aldri": 3,
"at": 1,