Skip to content

Instantly share code, notes, and snippets.

View SeriouslyAwesome's full-sized avatar

John Ellis SeriouslyAwesome

View GitHub Profile
@thelemonyfresh
thelemonyfresh / rails_anagram_finding.md
Last active August 31, 2022 21:14
Anagram finding in Rails, optimized.

TLDR

I optimize bulk anagram record creation from ~15 minutes (using the "naive" ActiveRecord approach) to ~10 seconds.

Intro

I'm making an app to practice for anagram games (think Scrabble, Words with Friends, etc.). Given a list of words, I need a way to quickly lookup anagrams that exist as words in that list.

I'll be using the TWL06 (tournament word list used for Scrabble in the US and Canada), which has ~180k words, stored as a .txt file separated with line breaks.

@thelemonyfresh
thelemonyfresh / load_tracer
Last active January 25, 2018 21:04
Print file names as rails app loads
# bin/rails
#
# drop the following into bin/rails to list files as they load -- useful for tracking down order dependency issues
files = []
tp = TracePoint.new(:line) do |tp|
if tp.path =~ /<repository_name>/
unless files.include? tp.path
puts "#{tp.path}".inspect
files.push(tp.path)
@mattlewissf
mattlewissf / add-p.md
Last active June 24, 2024 01:07
Lightning Talk: Git add -p

git add -p is your friend

git add -p is basically "git add partial (or patch)"

Patch mode allows you to stage parts of a changed file, instead of the entire file. This allows you to make concise, well-crafted commits that make for an easier to read history. This feature can improve the quality of the commits. It also makes it easy to remove parts of the changes in a file that were only there for debugging purposes - prior to the commit without having to go back to the editor.

It allows you to see the changes (delta) to the code that you are trying to add, and lets you add them (or not) separately from each other using an interactive prompt. Here's how to use it:

from the command line, either use

  • git add -p
@tylerhunt
tylerhunt / Gemfile
Last active October 11, 2023 14:44
ActiveAdmin association autocomplete without complicated plugins.
gem 'active_model_serializers'
gem 'activeadmin'
gem 'jquery-ui-rails'
@miharekar
miharekar / heroku_import.thor
Last active December 30, 2015 21:49
A simple thor script for imporing Heroku database into localhost. This is the original: http://antonzolotov.com/2012/03/04/rails-scripts-clone-heroku-database-to-development.html
#!/usr/bin/env ruby
module HerokuImport
class Db < Thor
method_option :keep, :type => :boolean, :default => false
method_option :remote, :type => :string, :default => "heroku"
method_option :host, :type => :string, :default => "localhost"
method_option :user, :type => :string, :default => `whoami`.strip
method_option :dbname, :type => :string
method_option :dump, :type => :string, :default => "latest.dump"
@koycarraway
koycarraway / _vars-social-colors.scss
Last active April 7, 2020 05:34
Sass color variables for popular brands and social media.
// Social Colors
// ====================================================================
$facebook_color : hsla(222, 47%, 40%, 1); // #365397
$twitter_color : hsla(198, 100%, 47%, 1); // #00a9f1
$linkedin_color : hsla(203, 100%, 35%, 1); // #006db3
$apple_color : hsla(0, 0%, 45%, 1); // #737373
$google_color : hsla(217, 89%, 61%, 1); // #4285f4
$google_plus_color : hsla(8, 74%, 53%, 1); // #e0452c
@bds
bds / gist:2207826
Created March 26, 2012 17:58
Convert files from .scss to .sass
sass-convert -F scss -T sass application_styles.css.scss application_styles.css.sass
@kagemusha
kagemusha / gist:1569836
Created January 6, 2012 09:20
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')