Skip to content

Instantly share code, notes, and snippets.

View bgkittrell's full-sized avatar

Ben Kittrell bgkittrell

View GitHub Profile
@bgkittrell
bgkittrell / center-prototype.js
Created October 17, 2010 02:26
Center Horizontal and Vertically using Prototype
Element.addMethods({
centerHorizontally: function(element) {
if (!(element = $(element))) return;
var vpWidth = $(document).viewport.getWidth();
var width = element.getWidth();
element.style.left = (vpWidth / 2) - (width / 2) + 'px';
return element;
},
<script>
(function(cont, meth) {
var index;
function log(){
console.log(index);
}
function iterate(){
log();
var Person = function(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var thomas = new Person('thomas');
var amy = new Person('amy');
@bgkittrell
bgkittrell / gist:704674
Created November 18, 2010 05:53
Reorder Multiple Elements ala Netflix
images = @album.image_assignments
changed = Array.new
# Get the images that changed order
for image in images
order = params["order_#{image.image_id}".to_sym]
if !order.blank? && order =~ /^\d+$/ && image.position.to_i != order.to_i
image.position = order.to_i
changed << image
<html>
<head>
<!-- Skin CSS file -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.2r1/build/assets/skins/sam/skin.css">
<!-- Utility Dependencies -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.8.2r1/build/element/element-min.js"></script>
<!-- Needed for Menus, Buttons and Overlays used in the Toolbar -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/container/container_core-min.js"></script>
http = require 'http'
fs = require 'fs'
util = require 'util'
connect = require 'connect'
uuid = require 'node-uuid'
require 'coffee-script'
UploadController = require './controllers/upload'
app = {}
@bgkittrell
bgkittrell / svnmv.rb
Created April 6, 2012 13:35
Ruby Script to Rename Files in Subversion
#!/usr/bin/ruby
require 'find'
Find.find('.') do |path|
if path =~ /#{ARGV[0]}/
puts path
new_path = path.gsub /#{ARGV[1]}/, ARGV[2]
puts new_path
module DoodlekitExtensions
module ContentFilter extend ActiveSupport::Concern
module ClassMethods
def content_filter(field, options = {})
before_save { |r| r.apply_filter(field)}
include DoodlekitExtensions::ContentFilter::InstanceMethods
end
end
@bgkittrell
bgkittrell / new
Created June 22, 2012 16:51 — forked from creich/new
<%= form_for @time_tracker, :url => {:action => :stop},
:html => {:class => "time-tracker-form",
:onchange => "updateForm()" }do |f| %>
<!-- TODO localize placeholders / add labels -->
<%= f.label l(:time_tracker_label_current_task) %>
<script>
updateForm = function() {
// prototype ajax request
new Ajax.Request(....
require 'rubygems'
require 'fog'
require 'find'
require 'set'
# create a connection
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'XXXXX',
:aws_secret_access_key => 'XXXXX'