Skip to content

Instantly share code, notes, and snippets.

View fjfish's full-sized avatar

Francis Fish fjfish

View GitHub Profile
# quick class to create seed data from an existing model
# http://intridea.com/2008/4/20/seed-fu-simple-seed-data-for-rails
# sd = MakeSeedData.new(MyActiveRecord)
# sd.generate # get all records
# sd.generate(MyActiveRecord.all(:conditions => ...))
#
# Generate returns a string, put it in a file in db/fixtures as per their
# instructions. It can be passed any array of objects that can pretend to be
# the base active records
#
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gc='git commit -v'
alias gca='git add . ;git commit -v'
alias gb='git branch'
alias gba='git branch -a'
module Paperclip
class Attachment
def url style = default_style, include_updated_timestamp = true
url = original_filename.nil? ? interpolate(@default_url, style) : interpolate(@url, style)
include_updated_timestamp && updated_at ? [url, updated_at].compact.join(url.include?("?") ? "&" : "?") : url
url.gsub(/s3\./,"s3-eu-west-1.")
end
end
end
# usage:
# generate_resource(Story)
# This generates the things you need to paste into data access
# classes when you're using the objective resource Objective C library
# http://iphoneonrails.com
# either save and load it or paste into a script/console session
def generate_resource(table)
cols = table.column_names.select { |c| !["created_at","updated_at"].include?(c)}.collect { |n| n.camelcase(:lower)}
theString = ""
@fjfish
fjfish / gist:1461638
Created December 11, 2011 17:18
Converting a JSON string date into a Ruby Time object
# Convert string of the form 2011-12-31T23:59:59+00:00 to a Ruby Time object
# I'm sure there's an easier way to do this.
def self.json_to_ruby_time(the_string)
string_elements = the_string.split /[-T:+]+/
string_elements.pop
Time.new *(string_elements.map(&:to_i))
end
@fjfish
fjfish / SearchableAdapter.java
Created June 30, 2012 15:48
Simple String Adapter for Android ListView that has a filter that gives whatever it finds and ignores word boundaries
package com.yourco.yourapp;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@fjfish
fjfish / bad-words
Created October 1, 2012 15:34
Plain text file of regexps to match "bad" words, e.g. using grep -fi bad-words *.txt
[^[:alnum:]]ahole[^[:alnum:]]
[^[:alnum:]]anus[^[:alnum:]]
[^[:alnum:]]ash[0o]le[^[:alnum:]]
[^[:alnum:]]ass[^[:alnum:]]
[^[:alnum:]]azz[^[:alnum:]]
[^[:alnum:]]bassterd[^[:alnum:]]
[^[:alnum:]]bast[ae]+rd[^[:alnum:]]
[^[:alnum:]]b[i1]+[a]*tch[^[:alnum:]]
[^[:alnum:]]bl[o0]+wj[o0]+b[^[:alnum:]]
[^[:alnum:]]boffing[^[:alnum:]]
@fjfish
fjfish / gist:5706122
Created June 4, 2013 13:57
Method to create a session object with poltergeist so you can play with it in IRB
# load this file to create a method that creates a capybara session you can play
# with in irb
require 'capybara'
require 'capybara/poltergeist'
require 'ext/capybara/session'
def session(driver = :poltergeist)
Capybara.register_driver :poltergeist do |app|
@fjfish
fjfish / gist:5720959
Created June 6, 2013 11:49
Little script to take a file of quotes either as an argument or from a redirect and turn it into a CSV that hootsuite will load.
#! /usr/bin/ruby
require 'date'
require 'set'
quotes = $<.readlines.map { |line| line.strip }
tag = "#unicorns"
url = "https://leanpub.com/unicorns"
@fjfish
fjfish / Create Form Fields
Created July 15, 2013 17:51
Put your list of form fields in, load the file in irb, and out pops the html ready to be edited without you having to do a lot of repetitive typing
def make_group col
<<-EOT
<div class="control-group">
<%= form.label :#{col}, class: 'control-label' %>
<div class="controls">
<%= form.text_field :#{col}, { class: 'input-xlarge' } %>
</div>
</div>
EOT
end