Skip to content

Instantly share code, notes, and snippets.

Francis Fish fjfish

View GitHub Profile
fjfish / check_migrations.rb
Last active Jul 20, 2017
Script to check if migrations in the structure.sql file match the ones on the file system
View check_migrations.rb
IO.readlines("db/structure.sql").each do |line|
if line["INSERT INTO schema_migrations"]
migration_id = line.split(/'/)[1]
puts "#{migration_id} is missing" if Dir.glob("db/migrate/#{migration_id}_*.rb").empty?
fjfish / find-bots
Created Jun 23, 2016
Find bots plaguing your apache installation
View find-bots
#! /bin/bash
# Get info xmrpc get the ip sort count sort for humans
cat /var/log/apache2/*log | grep xmlrpc | awk '{ print $1 '} | sort | uniq -c | sort -h
fjfish / models.rb
Created Nov 7, 2014
Automatic generation of rspec model tests and factories for factory girl
View models.rb
class Models
def self.generate what = :model
ActiveRecord::Base.descendants.each do |model|
def self.factory model
factory_file_name = "spec/factories/#{}.rb"
fjfish / purge_tags.rb
Created Aug 22, 2013
Remove all html (and probably xml) tags from an input string
View purge_tags.rb
def purge_tags taggy
gsub(/<\/?[a-z][a-z0-9[:space:]]*[^<>]*>/, '').gsub( /&[^;]+;|[\r\n]/,'').
gsub( /[<>]*/, '').strip
fjfish / combinations.rb
Created Jul 30, 2013
get the combinations for a table for laying out in cucumber
View combinations.rb
strings = ["Not Set", "Participant", "Manager"]
strings.product(strings).each do |pair|
puts sprintf("|1 |%-12s |%-12s |", *pair)
fjfish / Create Form Fields
Created Jul 15, 2013
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
View Create Form Fields
def make_group col
<div class="control-group">
<%= form.label :#{col}, class: 'control-label' %>
<div class="controls">
<%= form.text_field :#{col}, { class: 'input-xlarge' } %>
fjfish / gist:5720959
Created Jun 6, 2013
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.
View gist:5720959
#! /usr/bin/ruby
require 'date'
require 'set'
quotes = $< { |line| line.strip }
tag = "#unicorns"
url = ""
fjfish / gist:5706122
Created Jun 4, 2013
Method to create a session object with poltergeist so you can play with it in IRB
View gist:5706122
# 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 / bad-words
Created Oct 1, 2012
Plain text file of regexps to match "bad" words, e.g. using grep -fi bad-words *.txt
View bad-words
fjfish /
Created Jun 30, 2012
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;
You can’t perform that action at this time.