Skip to content

Instantly share code, notes, and snippets.

View stevedev's full-sized avatar

Steve Thompson stevedev

View GitHub Profile
@stevedev
stevedev / fb-album.css
Created August 15, 2012 16:52
Simple jQuery Facebook Album Script
#photo-container {
padding: 15px;
}
#photo-container a {
overflow: hidden;
display: block;
float: left;
border: 1px solid #cdcac6;
padding: 0;
# Mock columns for tables
list
user_id integer
items:
user_id integer
list_id integer
users_items:
user_id integer

Ruby:

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

PHP:

<?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
(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());
@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

# 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'
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
// Ruby:
def multiply_by_two(i)
i * 2
end
// PHP:
public function multiply_by_two($i) {
return $i * 2;
if Rails.env.development? || Rails.env.test?
...
ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'true'
...
end