Skip to content

Instantly share code, notes, and snippets.

Avatar
🌵
On a vision quest

Darren DarrenN

🌵
On a vision quest
View GitHub Profile
@DarrenN
DarrenN / LiftFunctorDataThing.js
Created Sep 14, 2018
Pull a field from an object and set the object to the value of that field in a new object
View LiftFunctorDataThing.js
// needs ramda.js
const enclose = curry((a, obj) => objOf(prop(a, obj))(obj))
var example = {'id': '123', 'foo': 'bar'};
enclose('id', example)
// {"123": {"foo": "bar", "id": "123"}}
@DarrenN
DarrenN / logging.rkt
Created May 13, 2018 — forked from Metaxal/logging.rkt
Simple usage of Racket's logging facility
View logging.rkt
#lang racket/base
; One way to define a logger
(define lg (make-logger 'my-logger))
; Define a receiver for this logger, along with a log level
(define rc (make-log-receiver lg 'error)) ; also try with 'debug
; Another way to define a logger, with additional forms
(define-logger lg2)
(define rc2 (make-log-receiver lg2-logger 'debug))
@DarrenN
DarrenN / net-lens.rkt
Created Jan 21, 2018
Fun with Lenses, structs and net/url in Racket
View net-lens.rkt
#lang racket/base
(require json
lens
net/url
net/url-string
net/head
racket/dict
racket/string)
@DarrenN
DarrenN / trace.log-rkt
Created Sep 1, 2017 — forked from greghendershott/trace.log-rkt
Make racket/trace output go to a logger
View trace.log-rkt
#lang racket/base
(require racket/format
racket/list
racket/match
racket/trace)
(provide (all-defined-out)
(all-from-out racket/trace))
@DarrenN
DarrenN / find-node.el
Created Jan 7, 2017
Dynamically add your Node.js bin path to exec-path in Spacemacs
View find-node.el
(defun dotspacemacs/user-init ()
;; Use whatever node is available
(setq node-path (mapconcat
'identity
(butlast (split-string (executable-find "node") "\\/")) "/"))
(add-to-list 'exec-path node-path t))
@DarrenN
DarrenN / js_http_code_constants.js
Last active Oct 27, 2016
HTTP Codes as ES6 Constants
View js_http_code_constants.js
// Success 2xx
export const HTTP_200_OK = 200;
export const HTTP_201_CREATED = 201;
export const HTTP_202_ACCEPTED = 202;
export const HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203;
export const HTTP_204_NO_CONTENT = 204;
export const HTTP_205_RESET_CONTENT = 205;
export const HTTP_206_PARTIAL_CONTENT = 206;
export const HTTP_207_MULTI_STATUS = 207;
View where-macro.js
syntax where = function(ctx) {
const binaryOps = ["or", "and", "==", ">", "<", "-", "+", "*", "/", "."];
const dummy = #`dummy`.get(0);
function matchNext(names) {
const marker = ctx.mark();
const next = ctx.next();
ctx.reset(marker);
return !next.done && names.includes(next.value.val());
}
@DarrenN
DarrenN / sexprs.peg
Last active Dec 4, 2015
PEG Sexprs
View sexprs.peg
{
function getType(def, head) {
switch (head) {
case "and":
case "or":
case "not":
return "booleanOperator";
case "eq":
case "ne":
@DarrenN
DarrenN / get-npm-package-version
Last active Jul 27, 2021 — forked from yvele/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
View get-npm-package-version
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
echo $PACKAGE_VERSION
@DarrenN
DarrenN / app.jsx
Created Jul 14, 2015
Use Material Design Lite's JS to handle layouts with React + Webpack
View app.jsx
/* jshint esnext:true */
'use strict';
import React from 'react';
import Header from './header';
import Workspace from './workspace';
import Footer from './footer';
// Manually call upgradeElement / MaterialLayout on the main layout div *AFTER* its been rendered in the DOM.
export default React.createClass({