Skip to content

Instantly share code, notes, and snippets.

@joeegan
joeegan / grid.js
Last active May 11, 2017 14:45
point free grid (missing shuffle)
const fill = curry((thing, start, end, data) => Array.prototype.fill.call(data, thing, start, end));
const shuffle = curry(data => data);
const chunk = curry(function group(n, list) {
return R.isEmpty(list) ? [] : R.prepend(R.take(n, list), group(n, R.drop(n, list)));
});
pipe(
fill(0, 9, 71),
fill(1, 0, 9),
shuffle,
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
act() {
console.log('this is what we want hit');
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
init: function(){
this._super();
setTimeout(() => {
if (!(this.isDestroyed || this.isDestroying)) {
Ember.run(() => {
this.set('message', 'bar');
});
(function() {
var params = /(?:&|\?)(.+)/g.exec(window.location.href);
var paramsObj = {};
if (params && Object.keys(params).length) {
params[1].split('&').forEach(function(strPair) {
var splitPair = strPair.split('=');
paramsObj[splitPair[0]] = splitPair[1];
});
}
import util.Random.nextInt
var choices = Array("rock", "paper", "scissors");
var results = Array("Draw!", "Player wins!", "Computer wins!");
def judge (humanChoice:String, computerChoice:String) = {
val humanIndex = choices.indexOf(humanChoice);
val computerIndex = choices.indexOf(computerChoice);
val resultIndex = (3 + humanIndex - computerIndex) % 3;
results(resultIndex);
@joeegan
joeegan / balance.js
Created October 2, 2012 23:42
javascript balance parentheses
function balanceA(arr) {
var filtered = arr.filter(function(item) {
return item.match(/(\(|\))/g)
});
function test(a) {
// these conditions are insane, there must be a far easier way of doing this...
@joeegan
joeegan / jsrecursion.js
Created September 30, 2012 22:19
javascript recursive sum and max
function sumNonRecursive(arr) {
var n = 0;
for (var i = 0; i < arr.length; i++) {
n = n + arr[i];
}
return n;
}
var numArray = [5,2,3];
@joeegan
joeegan / gist:3697073
Created September 11, 2012 09:03
optional regex - match any image extension
str.match(/(?:jpg|png|gif)/)
@joeegan
joeegan / app.js
Created September 3, 2012 17:53
simple tcp server that writes the data posted to it to an output file
var fs = require('fs'),
net = require('net');
var writeStream = fs.createWriteStream(__dirname + "/outfile.txt");
var server = net.createServer(function (socket) {
socket.on('data', function(data) {
socket.write(data);
writeStream.write(data);
console.log(data);
@joeegan
joeegan / JS1k.html
Created February 7, 2012 00:24
JS1k
<!doctype html>
<html>
<head>
<title>JS1k, 1k demo submission [ID]</title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="c" height=300></canvas>
<script>
// boilerplate...