Skip to content

Instantly share code, notes, and snippets.

View jonathanmarvens's full-sized avatar

Jonathan Barronville jonathanmarvens

View GitHub Profile

The following example uses the '::' operator which has a proposal already and a champion on the committee. Other than the bind operator, the example I give uses no new syntax (other than what is new to ES6), and could fairly easily be polyfilled - though I expect it could be optimized if implemented natively. If you haven't seen Clojure protocols, they allow for single dispatch polymorpism based on type, without the methods being defined as part of that type. In clojure, they use the first parameter, but for my proposal, it uses the receiver (this), and uses the bind operator to make the call look similar to a normal method call. While I haven't actually written an implementation of the Protocol class I demonstrate here, I've thought enough about it that I feel it could be done in a few different ways without too much complexity.

/**
  • The following module is a sampling of underscore methods conver
@jonathanmarvens
jonathanmarvens / naïve-reverse-polish-calculator.js
Last active December 26, 2015 01:19
A naïve JavaScript implementation of a reverse polish calculator.
var
ReversePolish
;
ReversePolish = {};
(function (exports) {
var
operations
;
function isPalindrome( string ) {
if ( string.length <= 1 ) {
return true;
}
if ( string.charAt( 0 ) !== string.charAt( ( string.length - 1 ) ) ) {
return false;
}
return isPalindrome( string.substr( 1, ( string.length - 2 ) ) );
( function () {
var
net,
sockets
;
net = this.require( "net" );
sockets = [];
net
@jonathanmarvens
jonathanmarvens / contracting-rate-info.js
Last active September 29, 2017 22:51
Use this little Gist to calculate your contracting rate information. It's a very simple formula. Note: *YMMV* ... my formula may or may not work for you.
function contractingRateInfo( options ) {
var
committed_days,
committed_days_cost,
committed_hours,
committed_hours_cost,
hourly,
weekly
;
( function () {
var DEFAULT_ENCODING_BASE = 2;
function _properBase( base ) {
if ( ! ( base === 2 || base === 16 ) ) {
base = DEFAULT_ENCODING_BASE;
}
return base;
}
def __constructor(*arguments, **keyword_arguments):
current_instance = arguments[0]
current_class = eval(current_instance.__class__.__name__)
parent_class = super(current_class, current_instance)
parent_class.__init__(*arguments[1:], **keyword_arguments)
__members = {
"__init__": __constructor,
}
<?php
// Resizer and Image Manipulation
// Based on: http://forums.laravel.com/viewtopic.php?id=2648
public function post_edit_logo($id)
{
$rules = array(
'image' => 'image',
);

Problem 1

Use JavaScript to write a function that takes a number as its argument. If the number is less than 10, the function should return "small"; if the number is 10 or greater, but less than 100, the function should return "medium"; if the number is 100 or greater, the function should return "large".

Problem 2

Use JavaScript to write a function that takes a number as its argument. If the number is between 1 and 10 (inclusive), return the word for that number (that is, if the number passed to the function is 2, return the word "two"). If the number is not between 1 and 10, return false.

<?php
class BaseController extends Controller {
private $application_name = 'The Cool Kid';
protected $layout = 'base';
// The cool kids' way of handling page titles.
protected $title = array(
'parent' => '',
'seperator' => '::',