Skip to content

Instantly share code, notes, and snippets.

@adelcambre
adelcambre / server.rb
Created September 26, 2013 17:27
A small bit of code to demonstrate the Sockets API in Ruby via a very tiny, very bad, web server.
require 'socket'
NOT_FOUND = "HTTP/1.1 404 Not Found\nContent-Length: 9\n\nNot Found"
OK = "HTTP/1.1 200 OK\n"
socket = Socket.new(:INET, :STREAM)
sockaddr = Socket.sockaddr_in(11080, '127.0.0.1')
socket.bind(sockaddr)
socket.listen(5)
@mmmries
mmmries / strict_tsv.rb
Last active December 16, 2015 16:09
Tab-separated parsing using Ruby 2.0 CSV library
# The main parse method is mostly borrowed from a tweet by @JEG2
class StrictTsv
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def parse
open(filepath) do |f|
headers = f.gets.strip.split("\t")
@bcarpio
bcarpio / lvsnapshot.sh
Created August 8, 2012 21:14
lvsnapshot.sh
#!/bin/bash
DATE=`date +"%a"`
DVOLNAME=datalv
LVOLNAME=journallv
VOLGR=datavg
DVOLPATH=/dev/$VOLGR/$DVOLNAME
LVOLPATH=/dev/$VOLGR/$LVOLNAME
DSNAME=`echo ${DVOLNAME}_ss_${DATE} | tr '[A-Z]' '[a-z]'`
LSNAME=`echo ${LVOLNAME}_ss_${DATE} | tr '[A-Z]' '[a-z]'`
@Randommood
Randommood / pg extensions
Created December 14, 2011 20:28 — forked from wayneeseguin/gist:1478154
List installed then available postgresql extensions
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
postgres=# \dx+
Objects in extension "plpgsql"
Object Description
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@mxcl
mxcl / uninstall_homebrew.sh
Created August 26, 2011 11:25
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@darrenterhune
darrenterhune / move logic to model
Created February 24, 2010 09:23
csv import example in model
# controller
def proc_csv
import = Import.find(params[:id])
if import.load_csv
flash[:notice] = "woo"
redirect_to some_url
else
flash[:error] = "ohoh"
end
end