Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joelnet
joelnet / MiniLinq.cs
Created May 13, 2011 07:28
Quick examples on how to use MiniLinq
// works in a similar way to LINQ with some minor differences.
using System;
using System.Collections;
using System.Runtime.CompilerServices;
namespace MiniLinqApi
{
[IgnoreNamespace]
internal static class MiniLinq
const user3 = {
password: 'Password!',
name: 'Naboo',
id: 300
}
const organize = ({ password, ...object }) =>
({ ...object, password })
// --------
// /
const user3 = {
password: 'Password!',
name: 'Naboo',
id: 300
}
const organize = object => ({ id: undefined, ...object })
// -------------
// /
// move id to the first property
const user = { id: 100, name: 'Howard Moon'}
const userWithPass = { ...user, password: 'Password!' }
user //=> { id: 100, name: 'Howard Moon' }
userWithPass //=> { id: 100, name: 'Howard Moon', password: 'Password!' }
const part1 = { id: 100, name: 'Howard Moon' }
const part2 = { id: 100, password: 'Password!' }
const user1 = { ...part1, ...part2 }
//=> { id: 100, name: 'Howard Moon', password: 'Password!' }
const partial = { id: 100, name: 'Howard Moon' }
const user = { ...partial, id: 100, password: 'Password!' }
user //=> { id: 100, name: 'Howard Moon', password: 'Password!' }
const setDefaults = ({ ...object}) => ({ quotes: [], ...object })
@joelnet
joelnet / once.sh
Created May 30, 2019 05:13
Shell script to execute a command once (while running)
#!/bin/bash
pidfile=$1
cmd=$2
if [ -z "$pidfile" ] || [ -z "$cmd" ]; then
echo "Usage: once <pidfile> \"<command>\""
exit 0
fi
@joelnet
joelnet / boolean-expressions-ski.js
Last active August 5, 2019 08:42
Boolean Logic with the SKI Combinators
// S and K are primitive function combinators.
const S = a => b => c => a (c) (b (c))
const K = a => b => a
// Non-primitive combinators can be created with S and K.
const C = S (S (K (S (K (S)) (K))) (S)) (K (K))
const I = S (K) (K)
const KI = K (I)
const M = S (I) (I)
const R = S (K (S (K (S)) (K))) (S (K (S (I))) (K))
@joelnet
joelnet / es6-proxy-set.js
Created August 20, 2019 17:11
ES6 Proxy Set
/**
* Demo for https://twitter.com/joelnet/status/1163820524709076992
*/
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}