Skip to content

Instantly share code, notes, and snippets.

View liamgriffiths's full-sized avatar

Liam Griffiths liamgriffiths

View GitHub Profile
@liamgriffiths
liamgriffiths / demo.jsx
Last active December 6, 2018 14:13
Sloppy switch/case demo in React.js/JSX
import React, { Component } from "react"
import ReactDOM from "react-dom"
import { Switch, Case } from "switch_case"
class App extends Component {
constructor() {
super()
this.state = {
value: false
@liamgriffiths
liamgriffiths / belsum
Created April 10, 2015 05:49
more cow bel
#!/bin/bash
# hear the md5sum of a file! ♬ ♬ ♬ ♬
# by liam (github.com/liamgriffiths)
function beat {
tput bel
}
function beats {
@liamgriffiths
liamgriffiths / Makefile
Last active August 29, 2015 14:10
hello world nasm
# osx nasm compile using macho64
NASM=/usr/local/bin/nasm
LD=/usr/bin/ld
all: hello
@./hello
hello: hello.o
@$(LD) -macosx_version_min 10.0 -o hello hello.o
@liamgriffiths
liamgriffiths / timers.js
Created November 7, 2014 04:24
timers in javascript/node.js
/**
* timers in action
* http://nodejs.org/api/timers.html
*/
// lastly this one is called, because it isn't resolved on the queue until ~50ms
// long after all the other functions are queued up in the event loop
setTimeout(function() {
console.log(5);
}, 50);
@liamgriffiths
liamgriffiths / css_transitions.md
Last active May 15, 2017 21:39
How to use CSS3 transitions

How to CSS3 transition

on the element that you want to transition you can apply the transition css property.

transition-property refers to the css property affected by the transition - for example (top, left, margin, color, etc)

transition-duration refers to the time the animation takes place

transition-timing-funcion refers to the way the transition is applied over the duration - ease

@liamgriffiths
liamgriffiths / cors.md
Last active February 23, 2024 13:15
How CORS works

Guide to CORS

CORS (cross origin resource sharing) is a mechanism to allow client web applications make HTTP requests to other domains. For example if you load a site from http://domainA.com and want to make a request (via xhr or img src, etc) to http://domainB.com without using CORS your web browser will try to protect you by blocking the response from the other server. This is because browsers restrict responses coming from other domains via the Same-Origin-Policy.

CORS allows the browser to use reponses from other domains. This is done by including a Access-Control headers in the server responses telling the browser that requests it is making is OK and safe to use the response.

Header Description
Access-Control-Allow-Origin: Allow requests from `` to access t
@liamgriffiths
liamgriffiths / traceroute.js
Last active September 22, 2023 16:36
traceroute clone in javascript
// sloppy traceroute clone
// inpired by https://blogs.oracle.com/ksplice/entry/learning_by_doing_writing_your
// and made possible by https://www.npmjs.org/package/raw-socket
var raw = require('raw-socket');
var dns = require('dns');
var target = process.argv[2] || '173.230.146.29';
var MAX_HOPS = 64;
var TIME_LIMIT = 5000;
@liamgriffiths
liamgriffiths / rotate90.scm
Created February 15, 2014 18:25
rotate a matrix 90 degrees to the right in scheme
(define (transpose m)
(apply map list m))
(define (rotate-90 m)
(transpose (reverse m)))
(define matrix
(list (list 'a 'b 'c 'd)
(list 'e 'f 'g 'h)
(list 'i 'j 'k 'l)

Big O notation (Asymptotic Notation)

The basic idea here is to give programmers a way to compare the performance of algorithms at a very high level in a language/platform/architecture independent way. This becomes particularly important when dealing with large inputs.

Big O notion may consider the worst-case, average-case, and best-case running time of an algorithm.

When describing an algorithm using Big O notation you will drop the lower-oder values. This is because when the inputs become very large, the lower-order values become far less important. For example:

Original Becomes