Skip to content

Instantly share code, notes, and snippets.

View stevedev's full-sized avatar

Steve Thompson stevedev

View GitHub Profile
gem install less -v 2.3.3 --no-ri --no-rdoc
@stevedev
stevedev / gist:6643892
Created September 20, 2013 21:05
How to Klass
class User < ActiveRecord::Base;end
klass = 'User'
Kernel.const_get(klass)
# => User(id: integer)
if Rails.env.development? || Rails.env.test?
...
ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'true'
...
end
// Ruby:
def multiply_by_two(i)
i * 2
end
// PHP:
public function multiply_by_two($i) {
return $i * 2;
process = fork do
File.open('./output.txt', 'w') do |f|
20.times do |i|
f.write "Tick #{i}\n"
f.flush
sleep 1
end
end
end
# Fun fact...
redirect_to some_path, notice: 'My notice'
redirect_to some_path, error: 'My error message'
# first will set a flash[:notice] while second will NOT set a flash[:error]
# vs:
flash[:notice] = 'My notice'
@stevedev
stevedev / gist:5628358
Created May 22, 2013 15:13
ActiveModel Filters idea

ActiveModel::Filters

Overview

Provide a ActiveModel::Validations style set of helpers for models to add input filters that work on all dirty fields before validation.

The point of this is I have a project that requires some data consistency and right now that's all ad-hoc and messy. I need a better way to quickly ensure that a username is lower case, things are trimmed properly before stored in the db, etc. Right now that's all done manually on the controller or model, or not at all.

Example Usage

(function($){
$.entwine('ss', function($) {
$('.ss-gridfield .action.userform-export-csv').entwine({
onclick: function(e){
var self = this, btn = this.closest(':button'), grid = this.getGridField();
var data = '';
// Add current button
data += '&' + encodeURIComponent(btn.attr('name')) + '=' + encodeURIComponent(btn.val());
<?php
/**
* Will save the object cache before object is completely destroyed.
*
* Called upon object destruction, which should be when PHP ends.
*
* @since 2.0.8
*
* @return bool True value. Won't be used by PHP

Ruby:

def factorial(n)
  return 1 if n.zero?
  1.upto(n).inject(:*)
end

PHP: