Skip to content

Instantly share code, notes, and snippets.

View paldepind's full-sized avatar

Simon Friis Vindum paldepind

  • Copenhagen, Denmark
  • 03:59 (UTC +02:00)
View GitHub Profile
// Getter a :: () -> a
// gmap :: ((a -> b), Getter a), Getter b
function gmap(fn, getter) {
return () => fn(getter())
}
// gcombine2 :: ((a,b) -> c, Getter a, Getter ab) -> Getter c
function gcombine2(fn, getter1, getter2) {
@mightybyte
mightybyte / location.hs
Created September 29, 2015 17:40
Reflex Location Management
------------------------------------------------------------------------------
-- | Gets the current path of the DOM Window (i.e., the contents of the
-- address bar after the host, beginning with a "/").
-- https://developer.mozilla.org/en-US/docs/Web/API/Location
getWindowLocationPathname :: DOMWindow -> IO String
#ifdef ghcjs_HOST_OS
getWindowLocationPathname w = do
jw <- toJSRef w
liftM fromJSString $ js_windowLocationPathname jw
@alexeygolev
alexeygolev / _record-syntax.js
Last active August 29, 2015 14:26
Extra stuff for union types
const Color = Type({RGB:[Number, Number, Number], CMYK:[Number, Number, Number, Number]});
const Color_ = Type({RGB:{Red: Number, Green: Number, Blue: Number}, CMYK:{Cyan: Number, Magenta: Number, Yellow: Number, Black:Number}});
const {Person} = Type({Person: {name: String, id: Number, leftEyeColor: Color_, rightEyeColor: Color}});
let person = Person({name: 'John', id: 1, leftEyeColor: Color.RGB(255,100,255), rightEyeColor: Color_.CMYK({Cyan: 50, Magenta: 80, Yellow: 10, Black: 25})});
let personWithoutEyes = Person('John', 2);
let person2 = personWithoutEyes(Color.RGB(100,100,100), Color.CMYK(30,30,30,0));
@raine
raine / ramda
Last active May 4, 2020 12:14
Browse Ramda documentation in Terminal
#!/usr/bin/env bash
# Browse Ramda documentation in Terminal
# Requires jq and a tool such as fzf or peco for interactive filtering
LATEST="http://raine.github.io/ramda-json-docs/latest.json"
DOCS_URL="http://ramdajs.com/docs/"
json=$(curl -s $LATEST)
functions=$(echo "$json" | jq -r '.[] | if .sig and (.sig | length > 0) then .name + " :: " + .sig else .name end')
@pH200
pH200 / cycle.js
Last active July 6, 2017 05:30
Small Todo by using Cycle.js
import Cycle, {Rx, h} from 'cyclejs';
Cycle.registerCustomElement('TodoList', (rootElem$, props) => {
let vtree$ = props.get('items$').map(items =>
h('div', h('ul', items.map((itemText, index) =>
h('li', { key: index + itemText }, itemText)))));
rootElem$.inject(vtree$);
});
let vtree$ = Cycle.createStream(function (interaction$) {
@danharper
danharper / gulpfile.js
Last active April 11, 2024 08:31
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
import Window
import Mouse
main = render <~ Window.dimensions ~ allMoves
mousePos =
let nomalize = \(w,h) (x,y) -> (toFloat x - toFloat w / 2, toFloat h / 2 - toFloat y)
in nomalize <~ Window.dimensions ~ Mouse.position
mouseDownAndPos = lift2 (,) Mouse.isDown mousePos
@twokul
twokul / hidden-classes-in-js-and-inline-caching.md
Last active April 23, 2024 22:02
Hidden classes in JavaScript and Inline Caching

Hidden classes in JavaScript and Inline Caching

Knowing how internals work is always a good. Pretty much for everything. Cars, trains, computers, you name it. It gives you an insight on what happens under the hood. You also act/react differently based on this knowledge.

As you might have guessed, it’s also true for web development. Knowledge of CSS transitions allows you to achieve better performance and not to use JavaScript in most cases. Knowledge of V8 internals allows you to write more performant JavaScript code. So let’s talk about V8 a little.

A little about V8

V8 is a JavaScript engine built by Google. Firefox built SpiderMonkey, Opera built Carakan and Microsoft built Chakra. One very important difference between V8 and other JavaScript engines is that V8 doesn’t generate any intermediate code. It compiles JavaScr

var $compileCache = function ($http, $templateCache, $compile) {
var cache = {};
return function (src, scope, cloneAttachFn) {
var compileFn = cache[src];
if (compileFn) {
compileFn(scope, cloneAttachFn);
} else {
$http.get(src, { cache: $templateCache }).success(function (response) {
var responseContents = angular.element('<div></div>').html(response).contents();
@cmeiklejohn
cmeiklejohn / .fonts.conf
Created November 18, 2011 02:57
fix debian chrome/chromium hinting problems since it doesn't obey the normal gnome settings
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font" >
<edit mode="assign" name="rgba" >
<const>none</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hinting" >