Skip to content

Instantly share code, notes, and snippets.

View mnpenner's full-sized avatar
:octocat:

Mark Penner mnpenner

:octocat:
View GitHub Profile
@mnpenner
mnpenner / driver.js
Created September 5, 2013 01:34
Selenium, PhantomJS, Node, Screenshots and Sizzle
var webdriver = require('selenium-webdriver');
var fs = require('fs');
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.phantomjs())
.build();
webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
return driver.takeScreenshot().then(function(data) {
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
@mnpenner
mnpenner / color.js
Last active July 9, 2016 15:01
RGB <-> HSL+HSL, for Node.js
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param {number} r The red color value
* @param {number} g The green color value
* @param {number} b The blue color value
* @return {array} The HSL representation
naughty becomes charsets
0x0027 0x005C 0x27 UCS-2 [\] UCS-2BE [\] UCS-2LE [尀] UTF-16 [\] UTF-16BE [\] UTF-16LE [尀]
0x0127 0x015C 0x27 UCS-2 [Ŝ] UCS-2BE [Ŝ] UCS-2LE [封] UTF-16 [Ŝ] UTF-16BE [Ŝ] UTF-16LE [封]
0x0227 0x025C 0x27 UCS-2 [ɜ] UCS-2BE [ɜ] UCS-2LE [専] UTF-16 [ɜ] UTF-16BE [ɜ] UTF-16LE [専]
0x0327 0x035C 0x27 UCS-2 [͜] UCS-2BE [͜] UCS-2LE [尃] UTF-16 [͜] UTF-16BE [͜] UTF-16LE [尃]
0x0427 0x045C 0x27 UCS-2 [ќ] UCS-2BE [ќ] UCS-2LE [射] UTF-16 [ќ] UTF-16BE [ќ] UTF-16LE [射]
0x0527 0x055C 0x27 UCS-2 [՜] UCS-2BE [՜] UCS-2LE [尅] UTF-16 [՜] UTF-16BE [՜] UTF-16LE [尅]
0x0627 0x065C 0x27 UCS-2 [ٜ] UCS-2BE [ٜ] UCS-2LE [将] UTF-16 [ٜ] UTF-16BE [ٜ] UTF-16LE [将]
0x0727 0x075C 0x27 UCS-2 [ݜ] UCS-2BE [ݜ] UCS-2LE [將] UTF-16 [ݜ] UTF-16BE [ݜ] UTF-16LE [將]
0x0827 0x085C 0x27 UCS-2 [࡜] UCS-2BE [࡜] UCS-2LE [專] UTF-16 [࡜] UTF-16BE [࡜] UTF-16LE [專]
@mnpenner
mnpenner / Custom_hg.xml
Created October 16, 2013 16:27
PhpStorm Command Line Tool support for Mercurial
<?xml version="1.0" encoding="UTF-8"?>
<framework xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schemas/frameworkDescriptionVersion1.1.3.xsd" name="Custom_hg" invoke="/usr/bin/hg" alias="hg"
enabled="true" version="2">
<help><![CDATA[Mercurial Distributed SCM]]></help>
<command>
<name>add</name>
<help>add the specified files on the next commit</help>
</command>
<command>
<name>addremove</name>
@mnpenner
mnpenner / Set.js
Last active December 22, 2015 02:59
Collects and compiles any .js, .css and .less files
module.exports = function(arr) {
var map = {};
this.contains = function(val) {
return map.hasOwnProperty(val);
};
this.add = function(val) {
map[val] = true;
};
function ordinal($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
$mod100 = $number % 100;
return $number . ($mod100 >= 11 && $mod100 <= 13 ? 'th' : $ends[$number % 10]);
}
@mnpenner
mnpenner / countries.json
Created January 5, 2015 02:58
Timezones
[{"timezones":["Europe\/Andorra"],"code":"AD","continent":"Europe","name":"Andorra","capital":"Andorra la Vella"},{"timezones":["Asia\/Kabul"],"code":"AF","continent":"Asia","name":"Afghanistan","capital":"Kabul"},{"timezones":["America\/Antigua"],"code":"AG","continent":"North America","name":"Antigua and Barbuda","capital":"St. John's"},{"timezones":["Europe\/Tirane"],"code":"AL","continent":"Europe","name":"Albania","capital":"Tirana"},{"timezones":["Asia\/Yerevan"],"code":"AM","continent":"Asia","name":"Armenia","capital":"Yerevan"},{"timezones":["Africa\/Luanda"],"code":"AO","continent":"Africa","name":"Angola","capital":"Luanda"},{"timezones":["America\/Argentina\/Buenos_Aires","America\/Argentina\/Cordoba","America\/Argentina\/Jujuy","America\/Argentina\/Tucuman","America\/Argentina\/Catamarca","America\/Argentina\/La_Rioja","America\/Argentina\/San_Juan","America\/Argentina\/Mendoza","America\/Argentina\/Rio_Gallegos","America\/Argentina\/Ushuaia"],"code":"AR","continent":"South America","name":"Argen
$.validator.setDefaults({
onfocusout: function(element, event) {
if(element.tagName === 'TEXTAREA' || (element.tagName === 'INPUT' && element.type !== 'password')) {
element.value = $.trim(element.value);
}
return $.validator.defaults.onfocusout.call(this, element, event);
}
});
exports.bindSelectDataFilter = function(select1, select2, dataAttr, backFilter) {
var $select1 = $(select1);
var $select2 = $(select2);
var $options = $select2.find('option'); // we need to cache these outside of the DOM; unfortunately this will break <optgroups>
var changeFunc = function() {
var $oldOption = $select2.find('option:selected');
var selectValue = $select1.val();
if(selectValue && selectValue != '0') {
$select2.html($options.filter(function() {
var dataValue = $(this).data(dataAttr);
var nunjucks = require('nunjucks');
var gaze = require('gaze');
var lib = require('nunjucks/src/lib');
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
// Node <0.7.1 compatibility
var existsSync = fs.existsSync || path.existsSync;