Skip to content

Instantly share code, notes, and snippets.

View dtipson's full-sized avatar

Drew dtipson

View GitHub Profile
@yahelc
yahelc / gist:1004702
Created June 2, 2011 16:02
Simpler Twitter Intents / Google Analytics Script
(function(){
var event_names = {
"click" : "" ,
"tweet" : "",
"retweet" : "source_tweet_id",
"follow" : "screen_name",
"favorite" : "tweet_id"
};
for(var event_name in event_names)
@yahelc
yahelc / jQuery-sharedcount.js
Created December 1, 2011 04:09
SharedCount JSONP/CORS jQuery plugin - Cache friendly
jQuery.sharedCount = function(url, fn) {
url = encodeURIComponent(url || location.href);
var arg = {
url: "//" + (location.protocol == "https:" ? "sharedcount.appspot" : "api.sharedcount") + ".com/?url=" + url,
cache: true,
dataType: "json"
};
if ('withCredentials' in new XMLHttpRequest) {
arg.success = fn;
}
@kylerush
kylerush / full.js
Created January 8, 2012 21:23
JavaScript epoch time convert number prototype
Number.prototype.timeLeft = function(){
var days = Math.floor(this / 86400);
var hours = Math.floor((this - (days * 86400)) / 3600);
var minutes = Math.floor((this - ((hours * 3600) + (days * 86400))) / 60);
var seconds = this - ((days * 86400) + (hours * 3600) + (minutes * 60));
@pazworld
pazworld / monad_law_tests.js
Created January 13, 2013 12:55
Monad law test for my Maybe monad.
// Test monad laws.
// Monad laws are described in http://www.haskell.org/haskellwiki/Monad_Laws
test("return a >>= f should be equivalent to f a", function() {
var f = function(a) { return Maybe.return(a * 3); };
var lhs = Maybe.return(5).bind(f);
var rhs = f(5);
deepEqual(lhs, rhs, "equivalent");
});
@quelgar
quelgar / jsmap.hs
Last active February 22, 2017 14:54
Is Javascript's array map function basically a comonadic cobind (=>> in Haskell)? Have a look as the jsmap function below.
-- Inspired by http://nedbatchelder.com/blog/201301/stupid_languages.html
-- which describes how the Javascript array.map function seems weird
-- and also http://blog.sigfpe.com/2008/03/comonadic-arrays.html
-- which describes the comonad for arrays
import Data.Array
import Data.Char
class Functor w => Comonad w where
(=>>) :: w a -> (w a -> b) -> w b
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'URL Encode',
'pi_version' => '1.1',
'pi_author' => 'Airtype Studio / BSD',
'pi_author_url' => 'http://www.airtypestudio.com/',
'pi_description' => 'Runs urlencode on a string of text.',
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'URL Encode',
'pi_version' => '1.1',
'pi_author' => 'Airtype Studio / BSD',
'pi_author_url' => 'http://www.airtypestudio.com/',
'pi_description' => 'Runs urlencode on a string of text.',
@divarvel
divarvel / continuation.js
Last active May 27, 2023 08:12
implementation of the continuation monad in JS
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof actual === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
@tel
tel / Lens.js
Created June 20, 2015 05:06
Really simple van Laarhoven lenses in Javascript
const IdModule = {
fmap: (fn) => (x) => fn(x),
}
const ConstModule = {
fmap: (fn) => (x) => x,
}
/**
@raine
raine / index.js
Last active October 6, 2015 17:36
const lineLens = lens(split('\n'), join('\n'));
const mapLines = curry((fn, str) =>
over(lineLens, map(fn), str));
const adjustLine = curry((fn, n, str) =>
over(lineLens, adjust(fn, n), str))
mapLines(toUpper, 'foo\nbar') // => 'FOO\nBAR'
adjustLine(toUpper, 0, 'foo\nbar') // => 'FOO\nbar"