Skip to content

Instantly share code, notes, and snippets.

Francis Fish fjfish

Block or report user

Report or block fjfish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fjfish
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?
end
end
@fjfish
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
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
Rails.application.eager_load!
ActiveRecord::Base.descendants.each do |model|
method(what)[model]
end
true
end
def self.factory model
factory_file_name = "spec/factories/#{model.name.underscore}.rb"
@fjfish
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
taggy.gsub(/\<style.*?\<\/style\>/mi,'').gsub(/\<script.*?\<\/script\>/mi,'').
gsub(/<\/?[a-z][a-z0-9[:space:]]*[^<>]*>/, '').gsub( /&[^;]+;|[\r\n]/,'').
gsub( /[<>]*/, '').strip
end
@fjfish
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)
end
@fjfish
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
<<-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
@fjfish
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 = $<.readlines.map { |line| line.strip }
tag = "#unicorns"
url = "https://leanpub.com/unicorns"
@fjfish
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
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
[^[: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 Jun 30, 2012
Simple String Adapter for Android ListView that has a filter that gives whatever it finds and ignores word boundaries
View SearchableAdapter.java
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.