Skip to content

Instantly share code, notes, and snippets.

View owskio's full-sized avatar

Theodore Robert Cackowski owskio

View GitHub Profile
@owskio
owskio / WhereAmIandWhatsGoingOn.bash
Last active September 24, 2015 12:27
WhereAmIandWhatsGoingOn
function ?
{
padleft=""; padright=""; title="$(pwd)"
padleftcount="$(( ($COLUMNS - ${#title})/2 ))"
while [ ${#padleft} -lt $padleftcount ] ; do padleft+=" "; done
function progress { echo $((${#padleft} + ${#title} + ${#padright})); }
while [ $(progress) -lt $COLUMNS ] ; do padright+=" " ; done
echo -e "\n\e[1;4;37;40m${padleft}${title}${padright}\e[0m"
ls "$@" && echo "";
}
@owskio
owskio / FunctionalEuler.js
Created November 27, 2011 16:36
FunctionalEuler
#!/sw/bin/js
function euler(firstPoint) {
print("Curr is:" + firstPoint)
function inner(passedPoint) {
var prevAsOuter = passedPoint
return function(currInner) {
print("\nPrev was:" + prevAsOuter)
print("Curr is:" + currInner)
//Rewrite the fn yet again so prev will be stored 4 next time
@owskio
owskio / CurryingAndCombinators.js
Last active August 29, 2015 14:04
Currying And Combinators Rock Together
//...
//While creating a 'trim' we get a 'remove' for free
//remove('cat','c') === 'at'; //true
remove = apply(flip(String.prototype.replace)('')),
//trim(' c ') === 'c'; //true
trim = flip(remove)([/^\s+|\s+$/g]),
//...
@owskio
owskio / NoMoreUnderscoreChains.js
Last active August 29, 2015 14:04
No more underscore chains
// ...
chain = flipAll(compose),
// ...
@owskio
owskio / Nice.js
Last active August 29, 2015 14:04
Nice
// ...
contains = function (haystack,needle) {
//NOTE: Case-Insensitive
return new RegExp(needle,'i').test(haystack);
},
containedBy = flip(contains),
// ...
@owskio
owskio / Useful.js
Last active August 29, 2015 14:04
Useful
// ...
clock = clockwise = function (fn) {
//WHY: Turns this:
// function (o,k,f) {};
// Into something which behaves like this:
// function (k,f,o) {};
return args(function (args) {
var last = args.pop();
@owskio
owskio / NonCurriedVariadicAccessorLenses.js
Last active August 29, 2015 14:04
Simple non-curried lens combinators assuming a single variadic accessor.
var a = 1,
l = proxy(console.log,console),
data = { a: { d: 1,b: { c: 3,e: 4 } } },
att = curry(function (a,o,v) {
//the following should also work
//return o[a] = v || o[a];
return v ? (o[a] = v) : o[a];
},2),
id = function (x) { return x; },
@owskio
owskio / MixedJqueryUnderscoreChaining.js
Created July 31, 2014 18:13
Chaining with both jquery and underscore functions simultaneously without an underscore context object
// ...
unQuery = function (fn) {
//Allows the usual context-style chaining
//but between all libraries.
return compose(flip(apply(fn)),arrayWrap);
},
// ...
$.fn.options = function (list) {
//PURPOSE: This plugin provides a useful
// abstraction for populating <select>
@owskio
owskio / AjaxDefaults.js
Last active August 29, 2015 14:04
Combinator Use Case: Adding AJAX Defaults
// ...
//AJAX DEFAULTS
basicAjax = addDefaults($.ajax,{
type: "GET",
dataType: 'json',
contentType: 'application/json',
error: function (jqXHR,textStatus,errorThrown) {
/* do some default error handling */
}
@owskio
owskio / ScopeDoping.js
Last active August 29, 2015 14:04
Eliminating library prefixes without JavaScripts with
//...
use = curry(function (obj,fn) {
//WHY: Implements qualified references in Javascript,
// without using Javascript's 'with'.
// Javascript doesn't allow us to alter the scope
// of a given piece of code programmatically without
// using 'with'. But 'with' has been labeled a 'bad
// part'. Because it is inefficient, and in some