Skip to content

Instantly share code, notes, and snippets.

View jlee42's full-sized avatar

Jeffrey Lee jlee42

View GitHub Profile
@jlee42
jlee42 / gist:2889647
Created June 7, 2012 15:57
Super awesome codes
if (awesome) { puts "Awesome." } else { puts "Refactor that shit." }
#
# Paperclip convert id => id_partition
#
require 'ftools' #FileUtils
class PaperclipExtend
def self.obtain_class
class_name = ENV['CLASS'] || ENV['class']
uploads_path = ENV['UPLOADS_PATH'] || ENV['uploads_path']
raise "Must specify CLASS" unless class_name
@jlee42
jlee42 / gist:2936854
Created June 15, 2012 14:54
Blackboard Transact Unix - PostgreSQL Triggers
-- Create a function to preform the timestamp update.
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
-- Create a trigger to run this function prior to an UPDATE on a row.
@jlee42
jlee42 / gist:3062069
Created July 6, 2012 18:57
invalid main GPT header
Last login: Fri Jul 6 09:25:53 on ttys004
jlee:~ jlee$ /usr/local/sbin/gdisk /dev/disk1
GPT fdisk (gdisk) version 0.8.2
Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!
Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table
@jlee42
jlee42 / txt2rtf.sh
Created July 6, 2012 18:59 — forked from gildotdev/txt2rtf.sh
Simple Bash script to create a rich text format file from a plain text file
#!/bin/sh
#check to see if arguments are set
E_BADARGS=65
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` textfilename [rtffilename optional]"
exit $E_BADARGS
fi
@jlee42
jlee42 / gist:3062087
Created July 6, 2012 19:00 — forked from peterwongpp/gist:2994714
My Shell Command Line Format - colored, with Git support and shortened
# return the current git branch name
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ →\ \1/'
}
# return the string of state of the branch
parse_git_dirty() {
D="$(git status 2> /dev/null | tail -n1 | awk '{ print $1 }' )"
if [ "$D" = "nothing" ] ; then
echo -e "(clean) "
@jlee42
jlee42 / mouseover.jquery.js
Created July 13, 2012 15:41
Unobtrusive JavaScript implementation of :mouseover for Rails 4.0 (jQuery)
$(document).ready(function(){
$('img[data-mouseover]').hover(function() {
$(this).data('_mouseover', $(this).attr('src'));
$(this).attr('src', $(this).data('mouseover'));
},function() {
$(this).attr('src', $(this).data('_mouseover'));
});
});
@jlee42
jlee42 / gist:3105581
Created July 13, 2012 15:43
UJS Mouseover Link Example
<%= link_to image_tag("logo.png", :'data-mouseover' => "/assets/logo-hover.png"), root_path %>
@jlee42
jlee42 / gist:3105603
Created July 13, 2012 15:47
Rails 3.2 deprecation of :mouseover
...
if mouseover = options.delete(:mouseover)
ActiveSupport::Deprecation.warn ":mouseover option is deprecated and will be removed from Rails 4.0"
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
options[:onmouseout] = "this.src='#{src}'"
end
...
@jlee42
jlee42 / strong_params_with_arrays.rb
Created November 3, 2012 19:12
Example of strong_parameters usage with arrays
params.require(:animal).permit(
:name, :description, :trainer_id, :photo_id, :video_id, :tag_list,
trainers_attributes: [:id, :first_name, :last_name, :_destroy]
)