Skip to content

Instantly share code, notes, and snippets.

View jonathanmarvens's full-sized avatar

Jonathan Barronville jonathanmarvens

View GitHub Profile
( function () {
var
net,
sockets
;
net = this.require( "net" );
sockets = [];
net
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 ) ) );
@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
;

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
module DataStructures
class NaiveLinkedList
def initialize()
@head = nil
end
def [](index)
node = @head
self.loop_set_node(index, node)
node.value()
if (! Function.prototype.bind) {
Function.prototype.bind = function bind(context) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind: the object on which you're trying to bind to is not callable.")
}
var
bound_func,
func,
var primeFactorization = function primeFactorization(number, result) {
var result = (result || []);
var root = Math.sqrt(number);
var x = 2;
if (number % x) {
x = 3;
while ((number % x) && ((x = (x + 2)) < root)) {}
}

THIS JUST IN: @WebandPHP Embrace Women in an attempt to Enhance PHPness and Boost Subscriptions

< sarcasm >

(PHP) -- A massive sexist storm spanning the globe dumped thousands of foreign messages on unsuspecting geeks as they watched as their tweet stream, normally depicting handy references to JS resources, object oriented design structures and REGEX utilities, turned into a thick sludge of sadness and despair, dividing the community.

Observers agreed, the divide also provided a distinct benefit by making easy work of identifying and arresting misogynist asshats who threaten the very fabric of a community, a community known for communicating using curly brackets, semi-colons and now, with PHP 5.3, namespaces.

Those detained now await no trail, but are able to exercise their right to a quick tagging and permanent display on the Geek Feminist Wiki.

function classExtend(subClass, superClass) {
for (var property in superClass) {
if (superClass.hasOwnProperty(property)) {
subClass[property] = superClass[property];
}
}
function constructor() {
this.constructor = subClass;
}
@jonathanmarvens
jonathanmarvens / README-dependency-resolver.md
Last active December 27, 2015 20:19
Simple dependency graph resolver. I needed this for a project, so if it can help someone else too, awesome :) . Of course you'll need to modify it for whatever your nodes' edges may be.

Example use.

var a = new Node("a");
var b = new Node("b");
var c = new Node("c");
var d = new Node("d");
var e = new Node("e");

a.addEdge(b); // a depends on b