Skip to content

Instantly share code, notes, and snippets.

View aleph-naught2tog's full-sized avatar

Max Cerrina aleph-naught2tog

View GitHub Profile
const fs = require('fs'); // the node file system package
const path = require('path');
// Usage:
// node file_tree.js name_of_folder_to_get_files_from
// node file_tree.js
// Either a passed-in-folder name (process.argv[2])
// or default to the current working directory
const folder = process.argv[2] || process.cwd();
@aleph-naught2tog
aleph-naught2tog / cors_wtf.md
Last active February 14, 2019 06:20
CORS notes

CORS wtf

preflight

tl;dr

  • yes, cross-origin includes different port numbers. to the IT students everyone pulling their hair out because two localhosts on your machine can't talk to each other: we salute you.
  • what is a simple request?
    • one of [GET, HEAD, POST] -- no side effects.
    • the ONLY manual (ie, not added by the browser) headers allowed are:
      • Accept
      • Accept-Language
  • Content-Language
@aleph-naught2tog
aleph-naught2tog / emotion_ts.ts
Last active January 5, 2019 00:31
Explanation below in comment
import { Omit, Overwrapped } from '@emotion/styled-base/types/helper';
import { Interpolation } from '@emotion/serialize';
import { WithTheme, StyledComponent } from '@emotion/styled-base';
// -------
// This is just to shush the compiler
type Theme = {};
type InnerProps = {};
@aleph-naught2tog
aleph-naught2tog / phoenix_notes.md
Created January 1, 2019 18:13
General phoenix notes

(NB: this was done initially for Phoenix 1.3 and I haven't updated it yet.)

phoenix

requirements

  • erlang
  • elixir
  • mix
  • phoenix

???

@aleph-naught2tog
aleph-naught2tog / postgresql.md
Created January 1, 2019 18:11
"Role 'postgres' does not exist"

Postgres

This was initially specifically in relation to errors when setting up Phoenix/Mix in relation to Postgres.

  1. From the command line: createdb. This creates the default database for the user you are currently logged in as.
@aleph-naught2tog
aleph-naught2tog / hello_asm.s
Last active December 30, 2018 05:32
Assembler
# hello_asm.s
# as hello_asm.s -o hello_asm.o
# ld hello_asm.o -e _main -o hello_asm -macosx_version_min 10.6 -lSystem
.section __DATA,__data
str:
.asciz "Hello world!\n"
.section __TEXT,__text
.globl _main
@aleph-naught2tog
aleph-naught2tog / bloop.md
Last active September 1, 2018 22:35
More regex readability comparisons

These two regular expressions are equivalent. Both use PHP's flavor of PCRE. (The first one might actually work for other languages PCRE variants as well, I'm not sure.) Neither will work for Javascript--it's pretty impossible to tell, but the first one does still have the conditionals, etc., as the second one. Just, you know, illegibly.

You'll have to horizontal-scroll a decent amount on that first one, too. (And also hope you never, ever, ever need to make changes.)

(?:((?:const)|(?:var))|(?:function))\s+(\w+)(?(1)(?:\s*=\s*(?:(?:function)(?:\s*\w+)?)?)|(?=\s*\())\(([^\)]*)\)(\h*=>\s*)?((?s)\s*\{\s*(?-s))?(?(5)([\s\S]*?)return\s)((?:\V++$\v)?(?:^\h+\V+$\v)*)(?(5)^\};?)

and:

@aleph-naught2tog
aleph-naught2tog / regex_whitespace.md
Last active August 25, 2018 22:25
Regex whitespace example

readable regex

Most languages allow a flag called the ignore-whitespace or free-spacing flag. Most of the major languages support it for their regular expression implementations -- with Javascript being the outlier here, as usual. Ruby, PHP, Elixir, etc., all support it. Java too.

What it does is makes it so that when the engine sees whitespace, it ignores it entirely.

So say we wanted to parse some HTML with regular expressions, like this:

/*
setup notes: needs the compiler option:
`"experimentalDecorators": true,` in your tsconfig
*/
function StaticImplements<T>() {
return (_constructor: T) => {};
}
interface Type<T> {
@aleph-naught2tog
aleph-naught2tog / readable.js
Last active April 29, 2018 18:41
Java API Sorting Bookmarklet
/*
For sorting the method tables by return type in the Java API.
To use: make a bookmarklet whose URL is exactly the following:
javascript:(function(){const%20TABLE_CLASS=".memberSummary";const%20ROWS_OTHER_THAN_FIRST_SELECTOR="tr:not(:first-child)";const%20methodTable=document.querySelector(TABLE_CLASS);const%20tbody=methodTable.querySelector("tbody");const%20allRows=tbody.querySelectorAll(ROWS_OTHER_THAN_FIRST_SELECTOR);const%20sortAlphabetically=(firstString,secondString)=>{if(firstString===secondString){return%200;}if(firstString<secondString){return-1;}if(firstString>secondString){return%201;}};const%20sortByInnerText=(firstHtmlElement,secondHtmlElement)=>{const%20firstText=firstHtmlElement.innerText;const%20secondText=secondHtmlElement.innerText;return%20sortAlphabetically(firstText,secondText);};const%20sortRowByFirstColumn=(firstRow,secondRow)=>{return%20sortByInnerText(firstRow.querySelector("td"),secondRow.querySelector("td"));};const%20sortByJdocRowId=(firstJavadocRow,secondJavadocRow)=>{c