Skip to content

Instantly share code, notes, and snippets.

@mando
mando / gist:7805553
Last active December 30, 2015 08:49
require 'timeout'
begin
timeout(1) do
sleep(5)
end
rescue Timeout::Error => e
puts e.inspect
end
@mando
mando / shrimp.sh
Created November 16, 2013 00:05 — forked from jcsalterego/shrimp.sh
#!/bin/bash
clear
echo -ne " \n\n\n\n"
echo -ne " a fantastic shrimp voyage\r"
sleep 2
echo -ne " * ( \r"
sleep 1
echo -ne " 9 ( \r"
sleep 1
#!/usr/bin/env ruby
num_times = (ARGV[0] || "1_000_000").gsub(/_/,'').to_i
seed = (ARGV[0] || Time.now).to_i
$stderr.puts "seed is #{seed}"
srand(seed)
time = Time.now.to_f
users = %w[Ace Beer Charlie Don Edward Freddie George Harry Ink Johnnie King London Monkey Nuts Orange Pip Queen Robert Sugar Toc Uncle Vic William Xray Yorker Zebra]
num_times.times do |user|
[~]$ ruby -Ku -e 'puts "Kevin Sjöberg".bytes.to_a.inspect' [ruby-1.8.7-p358]
[75, 101, 118, 105, 110, 32, 83, 106, 195, 182, 98, 101, 114, 103]
[~]$ ruby scratch.rb "Kevin Sjöberg" [ruby-1.8.7-p358]
[75, 101, 118, 105, 110, 32, 83, 106, 195, 182, 98, 101, 114, 103]
[~]$ [ruby-1.8.7-p358]
[~]$ cat scratch.rb

This is a test

get '/trackers/tumblr', :to=>'tumblr_trackers#index', :as=>'tumblr_trackers'
get '/trackers/tumblr/new', :to=>'tumblr_trackers#new', :as=>'new_tumblr_tracker'
post '/trackers/tumblr', :to=>'tumblr_trackers#create'
get '/trackers/tumblr-:id', :to=>'tumblr_trackers#show', :as=>'tumblr_tracker'
get '/trackers/tumblr-:id/edit', :to=>'tumblr_trackers#edit', :as=>'edit_tumblr_tracker'
put '/trackers/tumblr-:id', :to=>'tumblr_trackers#update'
delete '/trackers/tumblr-:id', :to=>'tumblr_trackers#destroy'
@mando
mando / gist:3815988
Created October 2, 2012 03:27
Time Zones say WHA?
$ rails -v
Rails 3.2.8
$ rails c
Loading development environment (Rails 3.2.8)
1.9.3-p194 :001 > Time.zone = 'Paris'
=> "Paris"
1.9.3-p194 :002 > t = Time.zone
=> (GMT+01:00) Paris # HUH? Paris is GMT+02:00 right now, thanks to DST
Now deep in the bowels of ActiveSupport::TimeZone, we have the following:
@mando
mando / gist:2579040
Created May 2, 2012 18:34
Mappings and such
[~]$ curl -XDELETE 'http://localhost:9200/tumblr' [ruby-1.9.3-p194@lab]
{"ok":true,"acknowledged":true}%
[~]$ cat mapping.json [ruby-1.9.3-p194@lab]
{ "mappings": {
"text": {
"properties": {
"blog_name": {"type": "string", "index":"not_analyzed"},
"timestamp": {"type": "date"}
}
},
#include <iostream>
#include <iomanip>
using namespace std;
void main ()
{
int iNum, i = 0;
while (i < 5)
{
cout << "Please enter a number: ";
#include <iostream>
#include <iomanip>
using namespace std;
void main ()
{
int iNum, i = 0;
while (i < 5)
{