Skip to content

Instantly share code, notes, and snippets.

View muraiki's full-sized avatar

Erik Ferguson muraiki

View GitHub Profile
@muraiki
muraiki / reduce_in_r.R
Created March 27, 2018 00:38
Calculating a rolling sum in R using the Reduce function
# Rolling sum using the Reduce function
EV <- c(1,.9,.8,.001,.001,.001,.001)
# Proportion of variance explained by each principle component.
prop_var <- EV / sum(EV)
# 0.3698224852 0.3328402367 0.2958579882
# 0.0003698225 0.0003698225 0.0003698225
# 0.0003698225
@muraiki
muraiki / pb.html
Last active January 22, 2018 16:50
Salesforce Process Builder: Generate formula code for matching multiple values
<form>
<label for="fieldName">Field name (include object):</label>
<input id="fieldName" name="fieldName" type="text" size="100" onkeydown="if (event.keyCode == 13) false">
</form>
<p>
<input type="checkbox" id="isPicklist" name="isPicklist" value="picklist">
<label for="isPicklist">Picklist?</label>
<input type="checkbox" id="isNot" name="isNot" value="not">
<label for="isNot">NOT?</label>
@muraiki
muraiki / 28.ijs
Created July 28, 2017 19:03
Generate series of 28 numbers in ascending order that total close to 1500 (J)
((,-)(2*>:&i.14))+(4*i.28)
@muraiki
muraiki / 28.apl
Created July 28, 2017 19:02
Generate series of 28 numbers in ascending order that total close to 1500 (APL)
https://ngn.github.io/apl/web/index.html#code=s%u21902%D71+%u237314%0Ax%u2190%28s%2C-s%29+%284%D7%u237328%29%0A%u2395%20%u2190x%5B%u234Bx%5D%0A%u2395%20%u2190+/x
s2×1+14
x(s,-s)+(4×28)
x[x]
+/x
@muraiki
muraiki / watch_source_files.p6
Last active September 4, 2015 12:32
Watch source files using Supplies
# disclaimer: I'm a perl6 noob :)
my $out = Supply.new;
$out.act: -> $s { say $s }; # actor model semantics; only ever execute this in 1 thread
my $watcher = IO::Notification.watch-path($*CWD.abspath)\
.grep(*.event.isa(FileChangeEvent::FileChanged))\
.unique(:as(*.path), :expires(1))\ # unique paths over last second, to prevent double-triggering from metadata events
.map(*.path.IO)\ # convert event path strings to IO::Path objects
.grep(*.extension eq 'p6')\
@muraiki
muraiki / watch_and_chown.p6
Last active August 29, 2015 14:28
Watch a file and chown it once it exists
my $PATH = '.';
my $USER = 'muraiki';
my $GROUP = 'staff';
IO::Notification.watch_path($PATH)\
.unique(:as(*.path), :expires(1))\
.map(*.path)\
.grep(* ~~ /\.sock/)\
.act(-> $socket {
say "Socket created: $socket"; # actually this happens for any I/O on the file, not just creation
@muraiki
muraiki / gist:077aef846a775028eec8
Created July 7, 2015 20:42
Intro to anonymous functions in Perl
# Intro to anonymous functions in Perl
use strict;
use warnings;
use feature qw(say);
use utf8;
binmode STDOUT, ':utf8';
# You can declare a sub without giving it a name. Hence, "anonymous" function.
sub { say 'this sub will never be called' };
@muraiki
muraiki / merge.pl
Last active August 29, 2015 14:19
merge two files
use strict;
use warnings;
open (my $foo, '<', 'foo.txt') or die;
open (my $bar, '<', 'bar.txt') or die;
open (my $merged, '>', 'merged.txt') or die;
print $merged '#!/bin/sh', "\n";
while (not eof $foo and not eof $bar) {
@muraiki
muraiki / gist:5cc72eaeb20a57da31bc
Created March 19, 2015 18:58
KO model with getters/setters and json update support
function FooModel () {
Object.defineProperties(this, {
_foo: {
value: ko.observable(x.name),
enumerable: true,
configurable: true
},
_bar: {
value: ko.observable(x.server_id || x.instance_id || x.instanceId),
enumerable: true,
@muraiki
muraiki / gist:96d746eff5f564c32990
Created March 19, 2015 18:54
updating KO model from json
// map the keys in json to the properties on your model
var desiredKeys = {
"foo": "foo",
"bar": "bar"
};
Object.defineProperty(self, 'updateFromJson', {
enumerable: true,
value: function (data) {
Object.keys(data)