Skip to content

Instantly share code, notes, and snippets.

@luxerama
luxerama / fizz_buzz.rb
Created August 14, 2013 13:03
Fizz Buzz
class Fixnum
def fizz_buzz?
self.fizz? and self.buzz?
end
def fizz?
self % 3 == 0
end
#!/bin/sh
exec ruby -x "$0" "$@"
#!ruby -w
class Foo
attr_accessor :bar
end
# instance
foo = Foo.new
###
# Allowable
#
# A pattern for decomposing large/long conditional chains
# into readable, testable, and inspectable segments.
# Code coverage stats can help show you which conditions
# aren't getting test coverage, and printing/prying around
# the code can show you intermediary condition results.
#
# Effectively a block-syntax for the `or` operator: each `when?`
@luxerama
luxerama / .zshrc
Created February 21, 2013 09:45
my current zshrc file with yadr
#
# Executes commands at the start of an interactive session.
#
# Authors:
# Sorin Ionescu <[email protected]>
#
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
@luxerama
luxerama / query.rb
Created November 14, 2012 12:29
Mongoid Moped query in order to get the distance returned by geospacial MongoDB queries
# This works as of Mongoid v3
Model.collection.database.command(geoNear: "models", near: [50, 50])
@luxerama
luxerama / rename_rails3.rb
Created June 20, 2012 08:58 — forked from vertis/rename_rails3.rb
Simple script that can be used to rename a rails3 app
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
def replace_in_file(filename,oldvalue,newvalue)
temp_file = Tempfile.new(File.basename(filename))
contents = File.read(filename)
changed_contents = contents.gsub(oldvalue,newvalue).gsub(oldvalue.downcase,newvalue.downcase)
temp_file.print(changed_contents)
@luxerama
luxerama / capistrano_database_yml.rb
Created May 24, 2012 14:03 — forked from weppos/capistrano_database_yml.rb
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <[email protected]>
# Copyright:: 2007-2010 The Authors
@luxerama
luxerama / test.coffee
Created May 15, 2012 16:02
Overriding batman.js model save
class Xyz.TestModel extends Batman.Model
save: (options, callback) ->
super options, (err, record, env) =>
console?.log record
testModel = new Xyz.TestModel()
testmodel.save null, (err) ->
@luxerama
luxerama / send_remote_syslog.php
Created May 13, 2012 21:06 — forked from troy/send_remote_syslog.php
Send UDP remote syslog message from PHP (RFC 3164)
<?php
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$msg = "<22>" . date('M j H:i:s ') . $program . ' ' . $component . ': ' . $message;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
# replace these with settings provided by Papertrail
socket_sendto($sock, $msg, strlen($msg), 0, 'logs.papertrailapp.com', 1111);
socket_close($sock);
}
@luxerama
luxerama / routing_helper.coffee
Created April 19, 2012 16:53
routeTo batman filter - This filter should cater for most routing applications
# Mixin to aid the compilation of routes
#
# PLEASE NOTE, this does not work with collections or nested routes/resources
#
# @mixin
# @author Vincent Siebert <[email protected]>
# @copyright (c) 2012 The Beans Group Ltd
Batman.mixin Batman.Filters,
# Filter to aid the compilation of non CRUD routes. Unfortunately because there is no way of resolving a keypath in an object when passing