Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<html ng-app='app'>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
</head>
<body ng-controller="defaultController">
</body>
<script>
var app = angular.module('app', []);
@tastywheat
tastywheat / multilinestring.js
Last active August 29, 2015 13:58
Javascript multiline strings
var commentContentsRegex = /\/\*!?(?:\@preserve)?[ \t]*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)\s*\*\//;
function multilinestring(fn){
return commentContentsRegex.exec(fn.toString())[1];
}
console.log(multilinestring(function (){
/*
something is up
@tastywheat
tastywheat / gist:f91da76cb12648678de8
Created July 15, 2014 15:38
Maybe Monad (sorta)
"use strict";
var maybe = function(expr){
var value;
try{
value = (typeof expr === 'function') ? expr() : expr;
}
catch(e){
value = null;
}
<!doctype html>
<html ng-app="app">
<head>
</head>
<body>
<div ng-controller="OneController" ng-controller="ThreeController">
<list list-onclick="doWork"></list>
</div>
<div ng-controller="TwoController">
@tastywheat
tastywheat / maybemonadv2.js
Last active August 29, 2015 14:04
maybemonad v2
function maybe(value){
var unit = {
bind: function(successHandler, failureHandler){
if(unit.isEmpty){
if(failureHandler) {
try{
failureHandler(unit.message);
}
catch(e){
unit.error = e;
@tastywheat
tastywheat / express-allow-cors.js
Last active August 29, 2015 14:04
allow cross domain ajax requests for cors
//http://enable-cors.org/server_expressjs.html
var allowCrossDomain = function(req, res, next) {
if(req.headers.host && req.headers.host === "127.0.0.1:4271"){
next();
}
else{
res.cookie('mycookie', 'bar', { domain: '.kpoppin.net' });
res.header('Access-Control-Allow-Credentials', true);
res.header("Access-Control-Allow-Origin", req.headers.origin);
function MyError(message){
this.message = message;
}
MyError.prototype = new Error();
try{
throw new MyError("message");
}
catch(e){
function math(value){
var unit = {
add: function(){
var args = Array.prototype.slice.call(arguments);
var sum = args.reduceRight(function(previousValue, currentValue, index, array) {
return previousValue + currentValue;
});
return math(sum + value);
},
multiply: function(number){
@tastywheat
tastywheat / layout-debug.css
Created September 1, 2014 19:27
debug css layouts
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
background-position: calc(100% - 50px) calc(100% - 20px);