Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
rewinfrey / heredoc_remove_leading_whitespace.rb
Last active August 29, 2015 14:02
Simple example for removing leading whitespace with Ruby's heredoc operator
# This is not as sophisticated as ActiveSupport's `strip_heredoc`, but is the simplest solution for
# removing leading whitespace.
# For more nuanced whitespace removal, take a look at http://apidock.com/rails/String/strip_heredoc
puts "With leading whitespace:"
puts <<-TEST
This is a test.
To remove leading spaces.
From Ruby's heredoc operator.
TEST
@runlevel5
runlevel5 / lotus_console.md
Last active August 29, 2015 14:02
A simple rake task that replicates the `rails console` for Lotus Framework

Lotus Console

A simple rake task that replicates the rails console for Lotus Framework

How to?

I assume that your config/application.rb is the place where you initialize all Lotus boot config

below is my config/application.rb for your interest

@rewinfrey
rewinfrey / rails_application_tuning.md
Last active August 29, 2015 14:04
Rails Large Application Tuning

Notes from Tuning Legacy Rails App: How to Make an Elephant Sprint

###Measuring performance

  • Monitor the values of specific code paths and graph them to see performance over time (response times as one example metric)
  • Automated tests that measure performance can fail based on a set threshold
    • If a given code path exceeds 20% of the existing response time, then the automated test fails, alerting ops and devs that a recent code change has negatively impacted performance beyond an pre-defined SLA or threshold
  • Need a production like environment
  • Make that performance test environment exclusive to performance testing (don't let regular usage or QA usage affect the test results)
  • Using NewRelic to compare boxes against each other
@rewinfrey
rewinfrey / struct_class.rb
Last active August 29, 2015 14:09
model like struct class
class Location < Struct.new(:city,
:state,
:zipcode)
def initialize(from_hash)
super(*from_hash.values_at(*members))
end
def display_city
city.capitalize
@solomonhawk
solomonhawk / example.js
Last active August 29, 2015 14:16
EZ Store Listening
// some pieces of this file have been omitted
let React = require('react')
let notesStore = require('../../stores/notesStore')
let monitorMixin = require('../../mixins/monitorMixin')
let Notes = React.createClass({
mixins: [monitorMixin(notesStore)]
// this gets called whenever `notesStore` emits a change event
@rewinfrey
rewinfrey / sql.txt
Created March 13, 2015 23:11
sql with negative look ahead
SELECT organizations.name,
organizations.id,
organizations.ancestry,
tmp.average_activated_time_of_children from organizations
JOIN (
SELECT org.ancestry,
AVG(org.updated_at - org.created_at) as average_activated_time_of_children,
CAST(substring(org.ancestry from '\d+(?!\/)$') as integer) as organization_id
FROM organizations org
INNER JOIN accounts acc ON acc.organization_id=org.id
/**
* Ref $elector Mixin
*/
export default {
$(ref) {
return this.refs[ref].getDOMNode()
}
}
@adomokos
adomokos / core_test.clj
Created May 15, 2015 18:53
Solving the Roman Numeral Kata in Clojure
(ns roman-numerals.core-test
(:require [clojure.test :refer :all]))
(def mapping {
0 ""
1 "I"
4 "IV"
5 "V"
9 "IX"
10 "X"
@alettieri
alettieri / wp_capistrano.rb
Created August 30, 2012 17:26
WordPress Capistrano deployment file (On Webfaction)
default_run_options[:pty] = true # Must be set for the password prompt from git to work
# WebFaction user account
# This is the server user account
set :server_user, "<server_username>"
# Server Domain
set :domain, "<domain_name>"
set :user, server_user
# Repository User
@novohispano
novohispano / seed.rb
Created November 5, 2013 18:06
Seeder example
class Seeder
def create_data
100.times do
create_user
create_event
end
end
private