Skip to content

Instantly share code, notes, and snippets.

View vindia's full-sized avatar

Vincent Oord vindia

View GitHub Profile
@vindia
vindia / license_checker.rb
Created June 25, 2021 19:36
List licences for a given Ruby project based on the Gemfile
require "bundler"
require "net/http"
require "json"
output = []
debug_mode = ARGV[0] == "--debug"
gems = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
@vindia
vindia / anagram.rb
Created October 31, 2017 13:25
Find anagrams in Ruby
require "benchmark"
time = Benchmark.measure do
words = File.read("wordlist.txt").downcase.split("\n")
anagrams = Hash.new{|hash, key| hash[key] = []}
words.each do |word|
root = word.chars.sort.join
anagrams[root] << word
end
# Find the whole number _n_ that consists of 10 digits
# (e.g. 3451209876) for which the first _k_ digits
# can be divided by _k_ with `2 <= _k_ <= 9`
#
# Examples:
# The first 2 digits of _n_ can be divided by 2 (`34` => true)
# The first 3 digits of _n_ can be divided by 3 (`345` => true)
# The first 4 digits of _n_ can be divided by 4 (`3451` => false)
# etc.
#
@vindia
vindia / used_colors.sh
Created August 25, 2015 13:08
Get all the color codes of colors used in your CSS file in a Rails project
grep -R 'color: #' app/assets/stylesheets/* | awk '{print $NF}' | sort | uniq
@vindia
vindia / anagram.rb
Created June 30, 2015 13:52
Anagrams! Mans agar! Arm a snag!
sentences = [
'Don’t like this trade.',
'Lets do it in the dark.',
'Foo bar'
]
sentences.each do |sentence|
puts sentence.downcase.gsub!(/[^a-z]/,'').split('').sort!.join('')
end
@vindia
vindia / sidekiq.rb
Created June 25, 2015 12:08
Initializer to use Sidekiq on Heroku
# config/initializers/sidekiq.rb
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = { size: 1 }
end
Sidekiq.configure_server do |config|
config.redis = { size: 9 }
end
@vindia
vindia / passcode.html
Created January 15, 2014 13:12
Trigger numpad on iPhone for password fields (e.g. when you want a user to enter a numeric passcode)
<fieldset>
<legend>Password with pattern <code>\d*</code></legend>
<label>Password: <input type="password" pattern="\d*"></label>
</fieldset>
<fieldset>
<legend>Password with pattern <code>[0-9]*</code></legend>
<label>Password: <input type="password" pattern="[0-9]*"></label>
</fieldset>
@vindia
vindia / remove_obsolete_branches
Created July 31, 2013 17:19
Remove obsolete branches in git
#!/bin/bash
# Remove all branches which are merged in to master
# Run this from within your repository, something like:
# cd /path/to/repo
# script/remove-obsolete-branches
#-----
BRANCH=${1:-'master'}
@vindia
vindia / too.rb
Created July 22, 2013 15:38
It's just too hot...
class Too
def hot
puts 'Yes...'
end
end
too = Too.new
too.hot
@vindia
vindia / email_domain.sql
Last active December 19, 2015 22:59
Select domain name from an email field in MySQL
SELECT email,
RIGHT(email, LENGTH(email) - LOCATE('@', email)) as domain
FROM `table`;