Skip to content

Instantly share code, notes, and snippets.

@Xananax
Xananax / redirect.html
Created March 11, 2018 16:16
A very simple page to redirect someone somewhere and get some info about them, similar to what bit.ly/goo.gl do
<!DOCTYPE html>
<html><head><meta charset="UTF-8">
<title>Redirection</title>
</head><body>
loading...
</body><script>
// change those:
var google_analytics_ua = 'UA-XXXXX-Y'
var next_url = "http://new-website.com"
// don't touch below:
@Xananax
Xananax / convert.sh
Created February 26, 2018 22:45
batch add filename to images
# Add a filename at the top of all jpegs in a given directory
# to write directly over the image, remove -splice 0x75
# to include the extension, use "%[f]" instead of "%[t]"
mogrify -pointsize 54 -background black -splice 0x75 -strokewidth 4 -fill black -stroke black -gravity north -annotate +0+20 "%[t]" -fill white -stroke none -annotate +0+20 "%[t]" *.jpg
@Xananax
Xananax / lambda.js
Last active May 13, 2019 17:16
Lambda calculus in js form
const Identity = a => a
const True = a => b => a
const False = b => Identity
const Condition = Predicate => Then => Else => Predicate(Then)(Else)
const And = Exp1 => Exp2 => Exp1(Exp2)(Exp1)
const Or = Exp1 => Exp2 => Exp1(Exp1)(Exp2)
const Not = Predicate => value => !Predicate(value)
const Defined = x => typeof x !== 'undefined'
// aliases
const T = True
@Xananax
Xananax / require_all.js
Created February 19, 2018 21:56
Require all files in a node project directory
const handlers = ( ( root = '', handlers = {} ) => {
const path = require('path')
const dir = path.join( __dirname, root ) // skip calling file (if it is in the same dir)
const index_file = path.join( dir, 'index.js' ) // skip index.js
require('fs').readdirSync(dir)
.filter( file => {
const curr = path.join(dir,file)
return ( /\.js/.test(file) && curr !== __filename && curr !== index_file )
} )
.map( file => file.replace(/\.js/,'') )
@Xananax
Xananax / TextFit.tsx
Created February 11, 2018 11:34
React Element for fitty.js
import * as React from 'react'
import { Component } from 'react'
import fitty, { Options, Fitted } from 'fitty'
export type Props = Partial<Options> & {text?:string} & React.AllHTMLAttributes<HTMLSpanElement>
export const style =
{ display: `inline-block`
, whiteSpace: `nowrap`
}
@Xananax
Xananax / Input.tsx
Created February 5, 2018 20:11
Basic React Input
/**
* Tired of re-typing the same component every time
* This is a component that takes a value prop OR
* handles value as a state, internally, OR
* does both.
*
* It can also trigger the onChange event throttled,
* instead of doing so on every key stroke
*/
@Xananax
Xananax / index.css
Created January 29, 2018 13:25
Simple chat interface example
html, body{
padding:0;
margin:0;
}
.main{
position: absolute;
display: block;
}
@Xananax
Xananax / eventEmitter.html
Last active January 25, 2018 01:16
A very very simple yet functional event emitter, to try to understand and discuss how events work
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Event Dispatcher example</title>
</head>
<body>
</body>
<script>
@Xananax
Xananax / run_apache_locally.md
Last active February 7, 2020 22:35
Run Apache Locally

Apache-serve

Runs apache locally

Usage

./serve <domain name> <document directory>
@Xananax
Xananax / typed_compose.ts
Created July 13, 2017 22:41
Typescript Typed Variadic Fold/Compose
export type Transformer<I,O> = (val:I)=>O
export type Promisable<I,O> = (val:I) => Promise<O>
export function composeSync<A,B>(a:Transformer<A,B>):(val:A)=>B
export function composeSync<A,B,C>(a:Transformer<A,B>,b:Transformer<B,C>):(val:A)=>C
export function composeSync<A,B,C,D>(a:Transformer<A,B>,b:Transformer<B,C>,c:Transformer<C,D>):(val:A)=>D
export function composeSync<A,B,C,D,E>(a:Transformer<A,B>,b:Transformer<B,C>,c:Transformer<C,D>,d:Transformer<D,E>):(val:A)=>E
export function composeSync<A,B,C,D,E,F>(a:Transformer<A,B>,b:Transformer<B,C>,c:Transformer<C,D>,d:Transformer<D,E>,e:Transformer<E,F>):(val:A)=>F
export function composeSync<A,B,C,D,E,F,G>(a:Transformer<A,B>,b:Transformer<B,C>,c:Transformer<C,D>,d:Transformer<D,E>,e:Transformer<E,F>,f:Transformer<F,G>):(val:A)=>G
export function composeSync<A,B,C,D,E,F,G,H>(a:Transformer<A,B>,b:Transformer<B,C>,c:Transformer<C,D>,d:Transformer<D,E>,e:Transformer<E,F>,f:Transformer<F,G>,g:Transformer<G,H>):(val:A)=>H