Skip to content

Instantly share code, notes, and snippets.

🐢
Turtles all the way

Marc Harter wavded

🐢
Turtles all the way
Block or report user

Report or block wavded

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wavded
wavded / gen.js
Created Apr 23, 2014
TCO in Generators
View gen.js
function* fibGen (current, next) {
yield current
yield* fibGen(next, current + next)
}
for (var num of fibGen(0,1));
// function* fibGen (current, next) {
// ^
// RangeError: Maximum call stack size exceeded
View gist:3fd800289a1dff2b9b66
if (!this.props.isInitialized) {
return (
<FlexRow>
<FlexColumn>
<EMap bingKey={this.props.bingKey} active={true} />
</FlexColumn>
</FlexRow>
)
}
View proto_inheritance.js
// Prototypal Inheritance (this function will eventually be in the JavaScript language)
if (typeof Object.create !== 'function') {
Object.create = function(o) {
function F() {}
F.prototype = o;
return new f();
}
}
View xhtml_base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
</body>
</html>
View singleton.js
var singleton = function() {
var privateVariable;
function privateFunction(x){
//privateVariable
}
return {
firstMethod: function(a, b) {
//privateVariable
},
secondMethod: function(a) {
View gist:252777
/* in few words:no round brackets=function or object, round brackets:anything, arguments.callee included.diff is the left assignment */
var a = function(){return 1}(); // 1
var b = function(){return {}}(); //object
function(){return 1}(); //error
function(){return {}}(); //error
var c = (function(){return arguments.callee})(); //function
var d = (function(){return []})(); //array
View gist:252771
/*
evaluates as a block — "{" and "}" — containing one labeled statement — `a:"a"`.
labeled statement, in its turn, evaluates to "a".
*/
{a:"a"}
/*
evaluates as an expression, where "(" and ")" are grouping operator and "{" and "}" constitute an object literal.
evaluates to this object value.
View gist:253421
var a = {};
//to note: nothing is passed in and no private variables/functions/etc. on purpose
var b = (function(){
return {};
})();
/*
Is there any difference between a and b in regards to scope/execution? Any advantage one has over the other? (besides like arguments.callee/recursive stuff);
*/
View geolocation.js
if (!navigator.geolocation) {
navigator.geolocation = (function (window) {
function getCurrentPosition(callback) {
// NOTE: for some reason, chaging the url is *allowed* with this service. Useful, but random
// source: http://www.maxmind.com/app/javascript_city
// The source is open source, as per: http://www.maxmind.com/app/api, but doesn't discuss specific license use. Hopefully it's just free to use - yay internet!
var geourl = 'http://j.maxmind.com/app/geoip.js_' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
View crockfordfacts.js
var sys = require("sys")
var http = require("http");
var twitter = http.createClient(80, "search.twitter.com");
var count = 10
for (var i = 1; i <= count; i++) {
var request = twitter.request("GET", "/search.json?q=crockfordfact+OR+crockfordfacts&rpp=100&page=" + i, {"host": "search.twitter.com"});
request.addListener('response', function(response) {
You can’t perform that action at this time.