Skip to content

Instantly share code, notes, and snippets.

View nchapman's full-sized avatar

Nick Chapman nchapman

View GitHub Profile
@nchapman
nchapman / expand.rb
Created May 12, 2011 20:17
Convert tabs to spaces
# ruby expand.rb /path/to/files
Dir["#{ARGV[0]}/**/*"].each do |file|
if file =~ /\.(rb|scss|css|erb|sql|conf|html|js)$/
`expand -t 2 #{file} > #{file}.tmp`
`mv #{file}.tmp #{file}`
end
end
local http = require "socket.http"
local function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
growMessageBody: function() {
var messageBody = $("message_body");
var rows = messageBody.value.split('\n').length;
if (rows <= 1)
rows = 2;
if (rows >= 10)
rows = 10;
class ActiveOhm < Ohm::Model
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
include Ohm::Boundaries
include Ohm::Callbacks
include Ohm::Timestamping
include Ohm::Typecast
require 'redis/list'
require 'redis/value'
class RedisModel
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :id
protected override void DataPortal_Update()
{
RaiseListChangedEvents = false;
using (SqlConnection cn = new SqlConnection(Database.LocalConnection))
{
cn.Open();
// loop through each deleted child object
// foreach (Sales deletedChild in DeletedList)
// // deletedChild.DeleteSelf(cn);
// DeletedList.Clear();
require 'erubis'
class Verb
def call(env)
base_path = File.join(Dir.pwd, env["REQUEST_URI"].sub(/\/$/, ""))
exact_path = base_path + ".rhtml"
index_path = File.join(base_path, "index.rhtml")
if File.exists?(exact_path)
render(exact_path, env)
SELECT HOUR(CONVERT_TZ(created_at, '+00:00','-07:00')) AS hour, COUNT(DISTINCT uuid) as count FROM hits WHERE DATE(created_at) = DATE(NOW()) GROUP BY HOUR(created_at);
require 'rubygems'
require 'fastercsv'
def normalize(row)
row[2].sub!(/^0+/, "")
row[3].sub!(/^0+/, "")
return row
end
old_rows = FasterCSV.read "old.csv"
// To get delimited values as an array
if (!string.IsNullOrEmpty(input))
items = input.Split(new[] { ",", " ", ";" }, StringSplitOptions.RemoveEmptyEntries);
// To put them back together with a standard delimiter
var output = string.Join(", ", items);