Skip to content

Instantly share code, notes, and snippets.

## convert somedomain.com to newhost.com
require 'rubygems'
require 'nokogiri'
require 'uri'
# change this to File.open
html_text = "<a href='http://somedomain.com/something/'>
<a href='http://somedomain.com/something/else'>"
html = Nokogiri::HTML(html_text)
donp@tower ~/src/parrot/parrot-3.1.0 $ perl Configure.pl
auto::byteorder - Compute native byteorder for wordsize.....little-endian.
auto::va_ptr - Test the type of va_ptr...
step auto::va_ptr died during execution: Unknown va_ptr type at config/auto/va_ptr.pm line 41.
at Configure.pl line 77
auto::format - What formats should be used for sprintf............done.
@donpdonp
donpdonp / gist:867752
Created March 13, 2011 00:49
Top 100 most frequent words
the 99
a 91
to 82
i 75
is 55
in 46
it 41
that 37
of 35
at 34
donp@sparky:~$ ruby -e 'puts "Hello World."'
Hello World.
donp@sparky:~$ jruby -e 'puts "Hello World."'
donp@sparky:~$
mysql> create table `test1` ( `id` int(32) );
Query OK, 0 rows affected (0.01 sec)
mysql> create table `test2` ( `id` int(32) ) ENGINE=InnoDB;
ERROR 1005 (HY000): Can't create table './socialigniter/test2.frm' (errno: 135)
mysql> show engines;
+------------+---------+----------------------------------------------------------------+
| Engine | Support | Comment |
+------------+---------+----------------------------------------------------------------+
@donpdonp
donpdonp / gist:893793
Created March 30, 2011 03:13
why ruby is better than java
## Ruby [1,2,3].each{|i| puts "I am #{i}"}
donp@sparky:~$ mirahc -j -e '[1,2,3].each{|i| puts "I am #{i}"}'
Parsing...
<inline script>
Inferring types...
Compiling...
DashE
Done!
## Java
@donpdonp
donpdonp / gist:893880
Created March 30, 2011 04:53
parallel ruby
$ cat parallel.rb
# parallel
work=["A","B"]
# Launch threads
work.map! do |job|
Thread.new do
puts "I got #{job}"
20000000.times { 4.0/2.0 }
@donpdonp
donpdonp / gist:912062
Created April 10, 2011 05:04
node.js/rb
## node.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
## node.rb(Goliath)
require 'goliath'
== AddRedirectionsModel: migrating ===========================================
-- create_table(:redirections)
NOTICE: CREATE TABLE will create implicit sequence "redirections_id_seq" for serial column "redirections.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "redirections_pkey" for table "redirections"
-> 0.2534s
Creating shortened URL for existing contents, this may take a moment
rake aborted!
An error has occurred, this and all later migrations canceled:
The single-table inheritance mechanism failed to locate the subclass: 'Page'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Content.inheritance_column to use another column for that information.
@donpdonp
donpdonp / gist:959762
Created May 6, 2011 20:55
rails-log-analysis
$ ./request-log-analyzer ~/Desktop/production.log
Request-log-analyzer, by Willem van Bergen and Bart ten Brinke - version 1.11.0
Website: http://railsdoctors.com
production.log: 100% [================================] Time: 00:01:01
Request summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Parsed lines: 443495
Skipped lines: 88