Skip to content

Instantly share code, notes, and snippets.

View voxpelli's full-sized avatar

Pelle Wessman voxpelli

View GitHub Profile
@voxpelli
voxpelli / README.md
Created June 25, 2014 13:32
My initial take on a JSHint .jshintrc config

If it is mainly a Node.js project that should be linted, then I would switch the "browser" setting for a "node" setting, but no matter if the default is that the javascript files are meant for a Node.js environment or a browser environment one can always override it in a specific file by adding the JSLint-compatible settings:

/*jslint node: true */

Or:

/*jslint browser: true */
@voxpelli
voxpelli / gist:3cb981f4fa65fc82f7f0
Created June 25, 2014 13:21
My initial take on a CSSLint .csslintrc config
{
"adjoining-classes": false,
"box-model": false,
"box-sizing": false,
"floats": false,
"gradients": false,
"ids": false,
"qualified-headings": false,
"text-indent": false,
"unique-headings": false,
@voxpelli
voxpelli / referrer-bookmarklet.js
Created April 25, 2014 13:04
Forgot from where a tab was opened? This bookmarklet helps you find out
// javascript:(function(){var%20result%20=%20window.prompt(%27You%20came%20here%20from:%27,%20document.referrer);if%20(result%20!==%20null)%20{window.open(result);}}())
(function(){
var result = window.prompt('You came from here:', document.referrer);
if (result !== null) {
window.open(result);
}
}())
@voxpelli
voxpelli / SASS_Calculcate_Alpha.md
Last active September 26, 2018 21:00
Pure SASS script for calculating the needed alpha channel of a top color to result in a target color on top of a specified bottom color.

A pure SASS-script to calculate what alpha channel that is needed for a color to achieve a certain target color when rendered on top of a specified bottom color.

This can be useful when extracting colors from a flat image where you can estimate two colors that are rendered on top of another, but need help with figuring out the alpha number of the top color to achieve the target color in the image.

Imagine eg. a sligthly transparent black box on top of an image. By color picking to adjacent pixels on the corner of the box – the one outside the box as the bottom color and the one in the box as the target color – and then specifying the top color as black and putting all of thos colors into this function – then you'll get back the approximate alpha color needed to achieve the wanted result.

Update 1: Addaded a function for also calculating what color to use to achieve a specific target color when the alpha channel is known (perhaps you have calculated the alpha for an adjacent element and want to figure out w

@voxpelli
voxpelli / ffDb.js
Created December 16, 2013 20:38
If using the ff npm-module to avoid nesting callbacks and wanting to init it with a fresh postgres connection for that very piece of callback handling (which is recommended to do postgres npm-module recommends for every request you handle in eg. Express), then this little snippet sets up a client as well as ensures that the connection is set fre…
var ffDb = function () {
var args = arguments, f;
Array.prototype.unshift.call(args, function () {
pg.connect(options.db, f.slotMulti(2));
}, function (client, done) {
f.pass(client);
f.onComplete(done);
});
@voxpelli
voxpelli / Gruntfile.js
Created October 20, 2013 12:22
Basic gruntfile
/*jslint node: true, white: true, indent: 2 */
"use strict";
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
dist: {
var oneDay = 86400;
module.exports = function (connect) {
var Store = connect.session.Store
, PGStore;
PGStore = function (options) {
var self = this;
@voxpelli
voxpelli / SASS_Color_Contrast.md
Last active August 21, 2022 11:49
Pure SASS script for calculating contrast ratios of colors. MOVED TO: https://github.com/voxpelli/sass-color-helpers

Pure SASS-adaption of Lea Verou's contrast-ratio javascript. Can be useful when eg. generating colored buttons from a single supplied color as you can then check which out of a couple of text colors would give the best contrast.

This script currently lacks the support for alpha-transparency that Lea supports in her script though.

In addition to the color-contrast adaption there's also some math methods that were needed to be able to calculate the exponent of a number and especially so when the exponent is a decimal number. A 2.4 exponent is used to calculate the luminance of a color and calculating such a thing is not something that SASS supports out of the box and not something I found a good pure-SASS script for calculating and I much prefer pure-SASS over ruby extensions. The math methods might perhaps be unecessary though if you're running Compass or similar as they may provide compatible math methods themselves.

Normal usage: `color: pick_best_color(#f00

@voxpelli
voxpelli / ajaxified-form.js
Created April 27, 2012 08:18
How to use the jQuery Form plugin together with the jQuery alterByObject plugin
(function () {
var handleModifyResponse = function (data, statusText, xhr, $form) {
if (data.targets) {
$form.alterByObject(data.targets);
}
};
$('form#epic-one').ajaxForm({
dataType: 'json',
success: handleModifyResponse
@voxpelli
voxpelli / activity.json
Created April 11, 2012 07:19
Draft for multi-verb Activity Streams activities
{
"items": [
{
"actor": {
"displayName": "pthulin",
"objectType": "person",
"url": "https://flattr.com/profile/pthulin"
},
"id": "tag:flattr.com,2012-04-11:pthulin/flattr/469010",
"object": {