Skip to content

Instantly share code, notes, and snippets.

View fjfish's full-sized avatar

Francis Fish fjfish

View GitHub Profile
@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 / 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 / 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
# 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 = ""
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
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'
# 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
#