Skip to content

Instantly share code, notes, and snippets.

export type COMPOSE = <T>(fn1: (a: T) => T, ...fns: Array<(a: T) => T>) =>
(a: T) => T
export const compose: COMPOSE = (fn1, ...fns) =>
fns.reduce(
(prevFn, nextFn) =>
(value) => prevFn(nextFn(value)),
fn1
);
@christianwish
christianwish / delete-local-branches.sh
Created January 31, 2019 09:28
delete all local git branches but not master
git branch | grep -v "master" | xargs git branch -D

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@jameslaneconkling
jameslaneconkling / baby-lisper.js
Last active August 23, 2022 00:32
A silly simple lisp parser in javascript
const rules = [
{ type: 'space', regex: /^\s/ },
{ type: 'lParen', regex: /^\(/ },
{ type: 'rParen', regex: /^\)/ },
{ type: 'number', regex: /^[0-9\.]+/ },
{ type: 'string', regex: /^".*?"/ },
{ type: 'variable', regex: /^[^\s\(\)]+/ } // take from the beginning 1+ characters until you hit a ' ', '(', or ')' // TODO - support escaped double quote
];
@DamnedScholar
DamnedScholar / language-sampleGrammar.cson
Last active January 25, 2023 20:14
Grammar boilerplate with annotations.
# TextMate tutorial: http://manual.macromates.com/en/language_grammars
# Regex to convert keys to unquoted: '(include|match|captures|begin|end|beginCaptures|endCaptures|name|patterns|0|1|2|3|4|5|6|7|8|9|comment|fileTypes|scopeName|repository|contentName|firstLineMatch|foldingStartMarker|foldingStopMarker)':
scopeName: 'source.<scope>' # <scope> should be a short, unique indicator for the language ("js", "php", "c", etc.)
name: '<name>' # The title that will show up in grammar selection and on your status bar.
fileTypes: [ # An array of file extensions.
'txt'
'exif'
]
@mrzmyr
mrzmyr / index.js
Created November 22, 2015 16:56
React Native - Detect Double Tap
var Index = React.createClass({
getInitialState: function () {
return {
lastPress: 0
}
},
onPress: function () {
var delta = new Date().getTime() - this.state.lastPress;
@tommy-muehle
tommy-muehle / prepare-commit-msg
Created June 30, 2015 10:31
Git hook to add JIRA issue key from branch-name (if it exists) and add it before the commit message
#!/usr/bin/env php
<?php
/**
* Add this file as "prepare-commit-msg" under /my-project/.git/hooks directory
* and make it executable. (chmod +x)
*
* Example:
* If Branchname was: "release/MYPRO-1-awesome-feature"
* and the commit message you typed in are: "Take this"
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active April 29, 2024 09:09
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@xeoncross
xeoncross / ajax.js
Last active August 3, 2023 06:06
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
@jexchan
jexchan / multiple_ssh_setting.md
Created April 10, 2012 15:00
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"