View core.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ajax-to-websocket.core | |
(:require [org.httpkit.server :as server] | |
[org.httpkit.client :as client] | |
[clojure.data.json :as json] | |
[clojure.data :as data] | |
[clojure.core.async :refer [chan <! >! go timeout onto-chan]])) | |
(defn channel-closed | |
"called when websocket channel is closed" | |
[status] |
View fib.pl6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subset NonNegativeInt of Int where * >= 0; | |
proto fib (|) is cached returns NonNegativeInt {*} | |
multi fib (0) { 0 } | |
multi fib (1) { 1 } | |
multi fib (NonNegativeInt $n) { fib($n - 1) + fib($n - 2) } | |
say fib(100) |
View gist:492539f842085f980349
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def groupBy[A](xs: List[A]): Map[A, Int] = | |
xs.foldLeft(Map[A, Int]()) { (m: Map[A, Int], x: A) => m + (x -> (m.get(x).getOrElse(0) + 1)) } |
View gist:96d746eff5f564c32990
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
View gist:5cc72eaeb20a57da31bc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
View merge.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
View gist:077aef846a775028eec8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' }; |
View watch_and_chown.p6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View watch_source_files.p6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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')\ |
View 28.apl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⍝ 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 | |
s←2×1+⍳14 | |
x←(s,-s)+(4×⍳28) | |
⎕ ←x[⍋x] | |
⎕ ←+/x |
OlderNewer