Skip to content

Instantly share code, notes, and snippets.

View mokolabs's full-sized avatar

Patrick Crowley mokolabs

View GitHub Profile
@waffleau
waffleau / extract_dominant_colors.rb
Last active March 27, 2024 10:22
Extract dominant colours from an image in Ruby using MiniMagick
def self.extract_dominant_colors(image_path, quantity=5, threshold=0.01)
image = MiniMagick::Image.open(image_path)
# Get image histogram
result = image.run_command('convert', image_path, '-format', '%c', '-colors', quantity, '-depth', 8, 'histogram:info:')
# Extract colors and frequencies from result
frequencies = result.scan(/([0-9]+)\:/).flatten.map { |m| m.to_f }
hex_values = result.scan(/(\#[0-9ABCDEF]{6,8})/).flatten
total_frequencies = frequencies.reduce(:+).to_f
@arjunvenkat
arjunvenkat / gist:1115bc41bf395a162084
Last active January 12, 2024 05:04
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@stalmok
stalmok / prevent-text-breakouts.css
Created August 14, 2012 05:38
CSS: Prevent Long URL’s From Breaking Out of Container
.prevent-text-breakouts {
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}
@supasympa
supasympa / updateShareThisButtons.js
Created December 5, 2011 14:54
Some code to update ShareThis buttons with custom images - useful in SPAs or AJAX apps
function updateShareButtons(location, title, imgsrc) {
$('.share').hide();
$('.sharethis').html('');
var services = [
{type : 'facebook',
image : './css/img/social-facebook.png'},
{type : 'twitter',
image : './css/img/social-twitter.png'},
{type : 'email',
@chrisyour
chrisyour / Folder Preferences
Created December 4, 2010 20:05
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern