Skip to content

Instantly share code, notes, and snippets.

(function() { // Make numbers look like strings
var oldToString = Number.prototype.toString;
Number.prototype.toString = function() {
if(this == 4) { return "four"; }
else { return oldToString.call(this); }
};
})();
var four = new Number(4);
alert(1 + four); // shows 5
val foo: Option[Set[Option[Char]]] = blah
val results = foo.map(_.map(_.map(bar).getOrElse(defVal))).getOrElse(Nil)
@xavi-
xavi- / gist:633087
Created October 18, 2010 21:21 — forked from jimbojw/gist:583389
Interview gist -- Can candidate read, debug, and fix code?
// For each of the following code fragments:
// a. what does the code do?
// b. what did the author intend for it to do?
// c. how would you fix it?
// NOTE: all code samples work exactly the same in all browsers
// 1. object literals
var data = [ { high: 100, low: 81 }, { high: 93, low: 73 }, { high: 60, low: 32 } ];
function getAverages(data) {
var avgs = [];
@xavi-
xavi- / gist:633341
Created October 19, 2010 00:15
Interview gist -- Can candidate write code?

Instructions

  • Solve all problems using JavaScript

Problems

  1. Write a function that returns an array with the first n powers of 2. Call it twoPow.

  2. Use twoPow and Array.prototype.reduce to the sum of the first 10 powers of 2.

  3. Describe this call signature:

// Create scrollLeft and scrollTop methods
jQuery.each( ["Left", "Top"], function( isScrollTop, name ) {
var method = "scroll" + name;
jQuery.fn[ method ] = function( val ) {
var elem, win;
if( val === undefined ) {
elem = this[ 0 ];
if( !elem ) {
@xavi-
xavi- / JS Lang Definition
Created March 27, 2011 15:40
My modified js language definition for textmate
{ scopeName = 'source.js';
comment = 'JavaScript Syntax: version 2.0';
fileTypes = ( 'js', 'htc', 'jsx' );
foldingStartMarker = '^.*\bfunction\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$';
foldingStopMarker = '^\s*\}';
patterns = (
{ name = 'meta.class.js';
comment = 'match stuff like: Sound.prototype = { … } when extending an object';
match = '([a-zA-Z_?.$][\w?.$]*)\.(prototype)\s*(=)\s*';
captures = {
@xavi-
xavi- / gist:1668685
Created January 24, 2012 07:31
Beeline in action
var http = require("http");
var bee = require("beeline");
var route = bee.route({
"`preprocess`": [
(function() {
function sendHtml(data) {
this.writeHead(200, { "Content-Length": data.length,
"Content-Type": "text/html; charset=utf-8" });
this.end(data);
var fs = require("fs");
var TwoStep = require("two-step");
var jsdom = require("jsdom");
TwoStep(
function() { fs.readFile("./cities.json", this.val()); },
function(err, cities) {
if(err) { throw err; }
cities = JSON.parse(cities);
@xavi-
xavi- / gist:3822327
Created October 2, 2012 18:48
My reddits
alternativeart
announcements
askscience
BarCraft
bestof
blockbattlenet
BuildingEsports
business
codeprojects
coding
@xavi-
xavi- / .jshintrc
Last active December 11, 2015 05:18
My JSHint settings.
{
"predef": [],
"maxerr": 150,
"browser": true,
"node": true,
"esnext": true,
"jquery": true,