Skip to content

Instantly share code, notes, and snippets.

View RShergold's full-sized avatar
💭
Currently alive

Remi Shergold RShergold

💭
Currently alive
View GitHub Profile
function el<K extends keyof HTMLElementTagNameMap>(
tagName: K,
props?: Partial<HTMLElementTagNameMap[K]> & {
ref?: (r: HTMLElementTagNameMap[K]) => void;
},
...children: Array<HTMLElement | string | null | undefined>
): HTMLElementTagNameMap[K] {
const element = document.createElement(tagName);
Object.assign(element, props);
@RShergold
RShergold / snake.hogg.io
Last active September 27, 2017 09:56
Heuristic algorithm for playing snake
/**
* @param {Array[Number]} cell Coordinates of the cell to return a value for
* @param {Number} xMax The number of cells across the x axis
* @param {Number} yMax The number of cells across the y axis
* @param {Array[Array[Number]} snake Coordinates of the position of the snake from head to tail. E.g. [[4, 1], [3, 1]]
* @param {Array[Number]} point Coorodinates of the point.
*/
function heuristic(cell, xMax, yMax, snake, point) {
let snakeHead = snake[0];
@RShergold
RShergold / swap keys and values with sublime replace
Created February 1, 2017 12:23
swap keys and values with sublime replace
text content:
'AF' => 'Afghanistan'
'AX' => 'Aland Islands'
'AL' => 'Albania'
'DZ' => 'Algeria'
...
(regex mode on)
find: ('\w\w') => ('.*')
replace: $2 => $1
@RShergold
RShergold / gist:d7456c62a94cae59a5decd0b86a24d7e
Created January 19, 2017 10:53
bash - test url response time
for i in {1..30};do curl -s -w "%{time_total}\n" -o /dev/null http://example.com; done
@RShergold
RShergold / isup.sh
Last active December 13, 2016 14:09
ping until website returns 200
#!/bin/bash
until [ $STATUS = "200" ]; do
STATUS=`curl -sL -w "%{http_code}\\n" "https://www.example.com/" -o /dev/null`
echo $STATUS
sleep 5
done
echo "Website back up"
osascript -e 'display notification "Website back up" with title "isup"'
{
"ensure_newline_at_eof_on_save": true,
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
@RShergold
RShergold / adventofcode.js
Created December 10, 2015 18:01
adventofcode day 9
var distances = `London to Dublin = 464
London to Belfast = 518
Dublin to Belfast = 141`.split("\n");
var cities = {};
var shortest = {distance:null, route:null};
//Turn the inputs into objects
for (var i=0; i<distances.length; i++) {
var distance = distances[i];
@RShergold
RShergold / adventofcode.js
Last active December 10, 2015 15:55
adventofcode day 7
var lines = `123 -> x
456 -> y
x AND y -> d
x OR y -> e
x LSHIFT 2 -> f
y RSHIFT 2 -> g
NOT x -> h
NOT y -> i`.split('\n');
function scroll_to(element, duration = 500, easing = 'easeInOutQuart') {
var start_pos = document.body.scrollTop,
end_pos = element.offsetTop,
distance = end_pos - start_pos,
start_time = Date.now(),
end_time = start_time + duration;
var easingFunctions = {
@RShergold
RShergold / fusker.html
Last active August 29, 2015 14:26
Imgur fusker
<style>
#images * {
width: 140px;
}
</style>
<p id='status'></p>
<div id='images'></div>
<button onclick='fusker.start()'>--go--</button>