Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/ruby
class ProgressMeter
attr_accessor :progress, :total
def initialize( total = 1 )
@progress, @total = 0, total
@old_str_size = 0
end
@CodeMonkeySteve
CodeMonkeySteve / mongodb
Created January 7, 2010 01:40
initscript for mongodb
#! /bin/sh
# start / stop script for mongodb
#
# mongodb - this script starts and stops the mongo daemon
#
# chkconfig: - 85 15
# description: Mongodb
# processname: mongod
# config: /etc/sysconfig/mongodb
# pidfile: /var/run/mongod.pid
class String
def possessive
str = self + "'"
str += 's' unless %r{(s|se|z|ze|ce|x|xe)$}i.match(self)
str
end
end

Ruby/Rails Style Guide

Whitespace

  • Use 2-space indentation (no tabs).
  • Remove trailing whitespace.
  • Use Unix-style line endings.
  • Use spaces around operators, after commas, colons and semicolons, around { and before }.
  • Use two spaces before statement modifiers (e.g. postfix if, unless, while, until, or rescue).
  • Use empty lines to break up a long method into logical paragraphs.
  • Keep lines to fewer than 132 characters.
@CodeMonkeySteve
CodeMonkeySteve / spec-support-webmock.rb
Created September 29, 2011 18:56
Webmock with RSpec
require 'pathname'
require 'webmock/rspec'
module WebMock
# pass-through these domains (e.g. "www.facebook.com")
Allow = %w().freeze
end
RSpec.configure do |config|
stubs = {}
@CodeMonkeySteve
CodeMonkeySteve / xliff_trans
Created March 2, 2015 19:33
XLIFF Translator
#!/usr/bin/env ruby
require 'bing_translator'
require 'active_support'
require 'active_support/core_ext'
class BingTranslator
@@cache = {}
@@cache_path = __dir__+'/.xliff_trans_cache'
@@cache = YAML.load_file(@@cache_path) if File.exist?(@@cache_path)
@CodeMonkeySteve
CodeMonkeySteve / iota-message.rb
Created May 31, 2021 21:21
IOTA API v1.5 (quick-n-dirty Ruby client)
module IOTA
class Message
attr_reader :id, :nonce
def initialize(node, id: nil, payload: nil)
@node = node
@id = id || (metadata && metadata[:messageId])
@payload = payload
@nonce = nil
end