Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
loretoparisi / gist:c147ca437ab9d5e163b7
Created October 23, 2015 22:01
Using JavaScript and k-means to find the dominant colors in images
<html>
<head>
<!-- adapted from http://charlesleifer.com/blog/using-python-and-k-means-to-find-the-dominant-colors-in-images/ -->
<script type="text/javascript">
function euclidean(p1, p2) {
var s = 0;
for (var i = 0, l = p1.length; i < l; i++) {
s += Math.pow(p1[i] - p2[i], 2)
}
@dalekunce
dalekunce / mac_gis_setup.md
Last active July 29, 2023 22:18
Yosemite GIS Machine Setup

Mac OS X GIS Setup

OS X Preferences


# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
@olvado
olvado / getAverageColourAsRGB.js
Created June 27, 2011 10:19
Get the average colour of an image in javascript using getImageData in CANVAS
function getAverageColourAsRGB (img) {
var canvas = document.createElement('canvas'),
context = canvas.getContext && canvas.getContext('2d'),
rgb = {r:102,g:102,b:102}, // Set a base colour as a fallback for non-compliant browsers
pixelInterval = 5, // Rather than inspect every single pixel in the image inspect every 5th pixel
count = 0,
i = -4,
data, length;
// return the base colour for non-compliant browsers
@joepie91
joepie91 / promises-faq.md
Last active June 25, 2023 09:02
The Promises FAQ - addressing the most common questions and misconceptions about Promises.
@dnprock
dnprock / client_example.html
Created September 24, 2013 18:58
Meteor image file upload. Then send file to S3.
Template.example.events({
'change input': function(ev) {
_.each(ev.srcElement.files, function(file) {
Meteor.saveFile(file, file.name);
});
}
});
@nhoizey
nhoizey / screenshots.js
Created November 12, 2012 17:07
Take screenshots at different viewport sizes using CasperJS
/*
* Takes provided URL passed as argument and make screenshots of this page with several viewport sizes.
* These viewport sizes are arbitrary, taken from iPhone & iPad specs, modify the array as needed
*
* Usage:
* $ casperjs screenshots.js http://example.com
*/
var casper = require("casper").create();
@javasteve99
javasteve99 / grid.css
Created June 28, 2012 18:45
A method for creating a grid overlay on your site. Allows you to easily align design elements to your grid.
/* ==========================================================================
Grid Overlay Styles
Author: Steve Hickey | http://stevehickeydesign.com
Company: Fresh Tilled Soil | http://freshtilledsoil.com
========================================================================== */
div#gridOverlay {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
width: 940px;
margin: 0 auto;
@evernotegists
evernotegists / b64dec.py
Created August 1, 2013 19:41
Convert base64-encoded data from an exported Evernote note back to its original form.
#!/usr/bin/env python
# Copyright 2013 Evernote Corporation. All rights reserved.
import base64
import sys
# Copy the base64 string from the ENEX file and put it into a file
# Pipe base64-encoded data to STDIN
@blowdart
blowdart / UpdateIISExpressSSLForChome.ps1
Last active October 7, 2021 10:59
IIS Express certs (for now) don't contain SAN strings. This makes Chrome unhappy. Make Chrome happy again with a new organic, artisanal, gluten free HTTPS certificate.
# Create a new self signed HTTPS Certificate for IIS Express
# Crafted with all organic, GMO, gluten free ingreditations
# with an artisinal SAN to make Chrome 58 onwards happy.
#
# See https://bugs.chromium.org/p/chromium/issues/detail?id=308330
#
# Run this at an administrative PowerShell prompt.
#
# You will be prompted to trust a new certificate via a windows dialog.
# Click yes otherwise Visual Studio will not be able to determine your
@impankratov
impankratov / handlebars.js
Last active September 8, 2021 15:59
Example of registering custom handlebars helpers (+ handlebars-form-helpers) with webpack
// Import Handlebars runtime lib
const Handlebars = require('handlebars/runtime');
const register = require('handlebars-form-helpers').register;
const { registerHandlebarHelpers } = require('../../some/other/place');
// Register extra helpers
register(Handlebars);
registerHandlebarHelpers(Handlebars);