Skip to content

Instantly share code, notes, and snippets.

View kalisjoshua's full-sized avatar

Joshua T Kalis kalisjoshua

View GitHub Profile
@kalisjoshua
kalisjoshua / pipe.js
Last active August 12, 2019 19:34
Simple utility function for "pipe-ing" values into functions because JavaScript doesn't have a Pipe (forward) operator... yet.
// Utility Function Definition
// A pipeline will call a series of functions pipe-ing output to input.
function pipe () {
return [].slice.call(arguments)
.reduce(function (acc, fn) {
return fn(acc)
})
}
// The above code compresses better then the ES2015 version.
@kalisjoshua
kalisjoshua / interesting.js
Created April 6, 2017 12:36
Collection of interesting JavaScript syntax.
// 1.
// replace instances with different replacement strings
const qwerty = 'qw#rt#'.replace(/#/g, [].shift.bind(['e', 'y']));
// 2.
// make Array.slice available as a function instead of a method
const slice = Function.prototype.call.bind(Array.prototype.slice);
// 3.
// ASI (failure) working in conjunction with the comma operator
#! /bin/bash
ROOT=/opt/fact
FACTORIO="$ROOT/factorio/bin/x64/factorio"
VERSION=$($FACTORIO --version | xargs echo | cut -d ' ' -f 2)
if [ "$1" = "start" ]; then
echo 'starting server'
# echo $$ > $ROOT/factorio.pid
function pubsubFactory() {
let subscribers = [];
const pub = publish;
const sub = subscribe;
const remove = unsubscribe;
function publish(message) {
if (!message) {
throw new Error('Not going to publish an empty message to subscribers.', 'pubsub.js');
}
@kalisjoshua
kalisjoshua / README.md
Last active July 1, 2016 15:45
Exploration of Curry-ing function in JavaScript

Curry-ing Functions In JavaScript

I don't know why, but this morning I felt like exploring function curry-ing and writing a little bit about it. First I watched a video on curry-ing from the JS Weekly newletter. Then I wanted to write my own implementation. After that I thought I would share what I did with my team at work and then this.

Brain-dump over.

The only reason I created two different implementations is becuase semantically I think that a function is only curried once; as I understand it - to curry - is a process by which you convert a single function which takes multiple arguments into a series of multiple functions each taking exactly one argument.

So, while the implementations work identically from the point of view of the user the differ in their implementation; basically only semantically.

@kalisjoshua
kalisjoshua / standardTraits.yaml
Created May 29, 2015 20:25
Standard Traits for RAML
standardDELETE:
responses:
200:
description: <<200description>>
body:
application/json:
example: <<200jsonExample>>
schema: <<200jsonSchema>>
202:
description: <<202description>>
// What does this code achieve?
function toArray(args) {
return Array.prototype.slice.call(args);
}
// When would you use it? Why does it need to be implemented this way? And what about the following code?
function log(args) {
Function.prototype.apply.call(console.log, console, args);
@kalisjoshua
kalisjoshua / ElevatorSaga.js
Last active December 10, 2021 21:07
Elevator Saga - Solution for challenges 1 through 12; still need to work on better efficiency.
{
init: function(elevators, floors) {
var TOP_LEVEL = floors.length - 1;
floors.requestQueue = [];
/**/
function _padd(len, str, char) {
str = '' + str;
while(str.length < len) {str = str + char;}
@kalisjoshua
kalisjoshua / SassMeister-input.scss
Created December 4, 2014 13:51
Generated by SassMeister.com.
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
@mixin size($size, $modulo: 5) {
@if $size % $modulo == 0 {
width: unquote('#{$size}%') !important;
}
}
@kalisjoshua
kalisjoshua / gist:500d5efabc7e848804af
Created June 8, 2014 14:14
IETF docs are ugly to look at and I am lazy so I don't like scrolling. This - bookmarklet (optional) - script makes the experience a little better with centered document body and larger text with left/right navigation through pages.
(function (doc) {
doc.body.style.fontSize = '115%';
doc.body.style.margin = '0 auto';
doc.body.style.maxWidth = '37em';
var count,
rPage = /\[\s*?page\s*?(\d+?)\s*?\]/i,
TOP = 'top-of-document';
function turn(delta) {