Skip to content

Instantly share code, notes, and snippets.

:octocat:

Mark Penner mnpenner

:octocat:
View GitHub Profile
View Model.php
<?php
namespace Expressive;
class Model extends \Eloquent {
protected static $fields = [];
protected static $unguarded = true;
function __construct(array $attributes = []) {
if(static::$fields) {
@mnpenner
mnpenner / Custom_hg.xml
Created Oct 16, 2013
PhpStorm Command Line Tool support for Mercurial
View Custom_hg.xml
<?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 / color.js
Last active Jul 9, 2016
RGB <-> HSL+HSL, for Node.js
View color.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
@mnpenner
mnpenner / driver.js
Created Sep 5, 2013
Selenium, PhantomJS, Node, Screenshots and Sizzle
View driver.js
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 / screenshot.js
Last active Dec 5, 2019
Save a screenshot with selenium-webdriver for JavaScript
View screenshot.js
var webdriver = require('selenium-webdriver');
var fs = require('fs');
var driver = new webdriver.Builder().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) {
if(err) throw err;
});
@mnpenner
mnpenner / Set.js
Last active Dec 22, 2015
Collects and compiles any .js, .css and .less files
View Set.js
module.exports = function(arr) {
var map = {};
this.contains = function(val) {
return map.hasOwnProperty(val);
};
this.add = function(val) {
map[val] = true;
};
View ordinal.php
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 / mode-mysql.js
Created Apr 16, 2013
MySQL mode for Ace editor. Based on existing pgsql mode with MySQL keywords and functions.
View mode-mysql.js
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
You can’t perform that action at this time.