Skip to content

Instantly share code, notes, and snippets.

@aghuddleston
aghuddleston / csv_for_excel.rb
Last active August 10, 2022 19:19
Write a CSV file using Ruby 2.2.2 which can open in Excel, properly displaying accents.
require 'csv'
module DownloadService
OPEN_MODE = "w+:UTF-16LE:UTF-8"
BOM = "\xEF\xBB\xBF" #Byte Order Mark
def student_list
File.open("#{file_name}.tsv", OPEN_MODE) do |f|
csv_file = CSV.generate({:col_sep => "\t"}) do |csv|
# header row
@staltz
staltz / introrx.md
Last active July 25, 2024 16:52
The introduction to Reactive Programming you've been missing
@blacktm
blacktm / install_ruby_rpi.sh
Last active May 26, 2024 15:13
A Bash script to install Ruby on the Raspberry Pi
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh)
# --------------------------------------------------------------------------------------------
# Set the Ruby version you want to install
@stevenharman
stevenharman / devise_mail_helpers.rb
Created August 14, 2013 02:23
Extract Devises "raw" tokens from outgoing email, since the tokens stored in the DB have been digested. (As for Devise 3.1)
module Features
module MailHelpers
def last_email
ActionMailer::Base.deliveries[0]
end
# Can be used like:
# extract_token_from_email(:reset_password)
def extract_token_from_email(token_name)
@sanand0
sanand0 / gitlab.sh
Last active December 28, 2020 20:13
Installing Gitlab
# Gitlab 5.1: https://github.com/gitlabhq/gitlabhq/blob/5-1-stable/doc/install/installation.md
# Set up an AWS EC2 Ubuntu 12.04 LTS Server.
# Use ap-southeast-1b: spot pricing is smoother
# Log in as ubuntu@
sudo apt-get -y update
sudo apt-get -y upgrade
# Install the required packages.
@eduardo
eduardo / thin.sh
Created May 9, 2012 02:36 — forked from me-vlad/thin.sh
init script for multiple thin instances with rbenv shared install
#!/bin/sh
# thin This shell script takes care of starting and stopping
# thin daemon from rbenv shared install
#
# chkconfig: 2345 85 15
# description: thin is an Ruby web server
# config: /etc/sysconfig/thin
### BEGIN INIT INFO
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@rondale-sc
rondale-sc / dndstats.rb
Created November 8, 2011 02:48
Down and Dirty Stats
require 'bigdecimal'
require 'csv'
require 'pp'
class Stats
include Enumerable
def initialize(array)
standardize_array(array)
end
@ches
ches / .pryrc
Created August 29, 2011 06:39
Enable Hirb in Pry, and hack disable/enable to work in-session
begin
require 'hirb'
rescue LoadError
# Missing goodies, bummer
end
if defined? Hirb
# Dirty hack to support in-session Hirb.disable/enable
Hirb::View.instance_eval do
def enable_output_method
@balupton
balupton / README.md
Last active July 13, 2024 17:32
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo