Skip to content

Instantly share code, notes, and snippets.

David Strauß stravid

Block or report user

Report or block stravid

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
View group_by_levenshtein.rb
emails = do |email|
grouping = emails
.group_by{|em| Levenshtein.distance(email, em) }
.select {|k,v| k < 5 && != 0 } # ignore exact matches and ones far off
if !grouping.empty?
[email, grouping]
0x263b /
Last active Oct 1, 2019
Random color from string in javascript

Random color from string in javascript

Consider a list of strings you need to permanently assign a random color.

First you should turn the string into a hash.

var string = "string"
var hash = 0
View bling.js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
NodeList.prototype.__proto__ = Array.prototype;
thbar / private_buckets_test.rb
Last active Aug 29, 2015
Production sanity test to verify that S3 buckets remain private over time
View private_buckets_test.rb
def buckets
def test_buckets_subdomain_private
buckets.each do |bucket_name|
gshaw / carrier_wave.rb
Created Aug 14, 2014
CarrierWave initialization file for testing with fixtures and support S3 in staging and production.
View carrier_wave.rb
# NullStorage provider for CarrierWave for use in tests. Doesn't actually
# upload or store files but allows test to pass as if files were stored and
# the use of fixtures.
class NullStorage
attr_reader :uploader
def initialize(uploader)
@uploader = uploader
clemens / invoice.rb
Created Jul 24, 2014
invoice number generation per year
View invoice.rb
class Invoice < ActiveRecord::Base
before_validation :generate_number, on: :create
def generate_number
prefix = "R#{'%y')}-"
last_order_number_this_year = self.class.where("number LIKE ?", "#{prefix}%").order("number DESC").limit(1).pluck(:number).first
number = last_order_number_this_year ? last_order_number_this_year.match(/\A#{prefix}(\d+)\z/)[1].to_i : 0
searls / app.css
Created May 18, 2014
Handy trick for debugging to see which parts of your app are being re-rendering in the DOM (without keeping your eyes glued to web inspector)
View app.css
body * {
-webkit-animation: fade-in 2s ease-out;
animation: fade-in 2s ease-out;
View What is a Product Manager?
Somebody asked me how to become a Product Manager. Here's what I wrote them.
Hi Jon,
Those are a lot of questions. Let me try to simplify it.
I think a Product Manager is a person who is responsible for determining
what a product should be and how it should evolve. This is a design role
View gist:7463148
div.description a.autolink
display: inline-block;
max-width: 250px;
text-overflow: ellipsis;
overflow: hidden;
maxhoffmann / gist:7373563
Last active Dec 27, 2015
run local php server and open browser
View gist:7373563
# local PHP Server
server() {
if [ -z "$1" ]; then
php -S $url & # run server in background
php -S $url -t $1 &
sleep 0.3s # wait for server to start
You can’t perform that action at this time.