Skip to content

Instantly share code, notes, and snippets.

View boogie666's full-sized avatar

Bogdan Bugarschi boogie666

  • Timisoara
View GitHub Profile
console.log 'fixing keybindigs'
atom.keymaps.keyBindings.forEach (x) ->
if x.keystrokes == 'g ^'
x.keystrokes = 'g shift-6'
x.keystrokeArray = ['g', 'shift-6']
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@boogie666
boogie666 / arp-lang.js
Last active February 12, 2018 11:56
a really bad, really slow, poorly coded, but turing complete version of a lisp :)
// a basic 'scope' for our language...
// it will never have globals...
// so it will thorw by default.
function ctx(name){
throw name + " is undefined";
}
/**
@boogie666
boogie666 / tiny-tiny-lisp.js
Last active April 6, 2018 07:44
128 char lisp interperter
//the interperter
e=(s,c)=>s/s?s:s.trim?c(s):(S=s[0],S=="if"?e(s[1],c)?e(s[2],c):e(s[3],c):S=="f"?a=>e(s[2],n=>s[1]==n?a:c(n)):e(S,c)(e(s[1],c)));
//global ctx
function global_scope(name){
if(name === "log")
return item => console.log(item);
if(name === "+")
return a => b => a + b;
if(name === "<")
@boogie666
boogie666 / click_position.js
Last active May 23, 2018 10:44
Example Transducer for tim.js
// example of get the position of the cursor in a line of a text buffer from a click event
function clickPositionToCharIndex(clickX){
return comp(
map(measureCharWidth),
reductions((a,b) => a + b, 0),
takeWhile(x => x < clickX),
mapIndexed((idx, item) => idx)
);
}
@boogie666
boogie666 / index.js
Created May 24, 2018 09:30
Finding pairs in a stream of data using windowing
require("./array.js");
const { reduce, reduced } = require("./reduce.js");
const { map, dropWhile, dedupe, window, comp } = require("./transducers.js");
const { into } = require("./into.js");
function pair_items(items){
items = into([], dropWhile(x => x.hasOwnProperty("pair_id")), items);
var first = items[0];
items.shift();
(defn- -create-react-component
"create a 'inline' component and set the display name to the same name as the function"
[f]
(let [component (fn [js-props]
(let [args (.-uixprops js-props)]
(hiccup->react (apply f args))))]
(set! (.-displayName component) (.-name f))
component))
;; obvious optimization if obvious
@boogie666
boogie666 / run-fsm.js
Created May 15, 2019 09:59
simple finite state machine runner
function run(fsm, stateRunner, state){
let runner = stateRunner[state.currentState];
return Promise.resolve(runner(state)).then(function(transition){
if(transition.transitionTo === "done"){
return transition.data;
}
return run(fsm, stateRunner, {
...transition,
currentState: fsm[state.currentState][transition.transitionVia]
});
@boogie666
boogie666 / fsm-state-runner.js
Last active May 15, 2019 10:06
fsm state runner 'api'
function checkLogin(state){
if(state.data.username == "admin"){
return {
...state,
transitionTo: "valid"
};
}else {
return {
...state,
transitionTo: "invalid"
@boogie666
boogie666 / full-example.js
Last active May 15, 2019 10:17
Full code example
//define the finite state machine data structure...
let fsm = {
"checkLogin" : {"valid" : "login",
"invalid" : "showError"}
};
//create the handler functions...
function checkLogin(state){
if(state.data.username == "admin"){
return {