Skip to content

Instantly share code, notes, and snippets.

View arnorhs's full-sized avatar

arnorhs arnorhs

View GitHub Profile
@arnorhs
arnorhs / bookmarklet-version
Created December 11, 2011 08:28
A simple snippet you can add to your bookmark bar (insert javascript: in front) to measure rendering performance of a state of a webpage
javascript:(function (window,$,runs) { var t = new Date(), i = 1, timetaken,offset = $(window).scrollTop(); $(window).bind('scroll.scrolltest',function () { if (i >= runs) { timetaken = (new Date) - t; console.log('Time taken for '+runs+' scrolls: ',timetaken,' - time per scroll: ', timetaken/runs); $(window).unbind('scroll.scrolltest'); return; } i++; doScroll(); }); function mod (x,y) { return Math.round((x/y - Math.floor(x/y)) *2); } function doScroll () { setTimeout(function(){ $(window).scrollTop(offset + mod(i,2)*100); },0); } doScroll(); })(window,jQuery,500);
@arnorhs
arnorhs / TodoApp.jsx
Last active May 16, 2023 17:24
ChatGPT gave me these two apps when proompting for: "write TODO application in react" and followed up with "That's great. Now can you port the same application to vanilla javascript using no framework"
import React, { useState } from 'react';
const TodoApp = () => {
const [todos, setTodos] = useState([]);
const [inputValue, setInputValue] = useState('');
const addTodo = () => {
if (inputValue !== '') {
const newTodo = {
id: Date.now(),
@arnorhs
arnorhs / gist:1509904
Created December 22, 2011 10:53
gitopen - Open all files from a git diff or show command
#!/bin/bash
# This script will open all files from a git diff or a git show in vim.
# My bash skills are a bit primitive so this can probably be done more intelligently
# Usage:
# gitopen -- opens all added files that have changed since HEAD
# gitopen diff HEAD -- these are the default parameters
# gitopen diff master -- opens files that have changed from master
@arnorhs
arnorhs / gist:1517095
Created December 24, 2011 10:40 — forked from tessro/gist:1515117
gitopen - Open all files from a git diff or show command
#!/bin/bash
# This script will open all files from a git diff or a git show in vim.
# My bash skills are a bit primitive so this can probably be done more intelligently
# Usage:
# gitopen -- opens all added files that have changed since HEAD
# gitopen diff HEAD -- these are the default parameters
# gitopen diff master -- opens files that have changed from master

Framendaþýðingar

enska ísl
container innihaldari
wrapper umvafningur
animation kvikun
transform ummynda
@arnorhs
arnorhs / kill_gatsby.sh
Created June 18, 2020 12:51
kill gatsby
#!/bin/bash
# Honestly there must be an easier way to do this, but im a noob
PSAUX="$(ps)"
while IFS= read -r line; do
if [[ $line == *"gatsby develop"* ]]; then
id=$(echo $line | cut -d " " -f 1)
kill -9 $id
/**
* from https://stackoverflow.com/a/49434653
*/
export const boxMullerTransformedRand = (): number => {
let u = 0, v = 0
while (u === 0) u = Math.random() //Converting [0,1) to (0,1)
while (v === 0) v = Math.random()
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v)
num = num / 10.0 + 0.5 // Translate to 0 -> 1
if (num > 1 || num < 0) return boxMullerTransformedRand() // resample between 0 and 1
@arnorhs
arnorhs / logger.js
Created May 20, 2020 23:30
returning named logger
const logger = (label, printer = null) => (...args) => {
(printer || console.log)(`[${label}]`, ...args)
const [first] = args
return first
}
export default logger
// example usage:
const log = logger('user clicked button')
@arnorhs
arnorhs / String hash code
Created May 3, 2020 13:48
string hash code
const strHash = str => {
let hash = 0
for (let i = 0; i < str.length; i++) {
let charCode = str.charCodeAt(i)
hash = (hash << 5) - hash + charCode
hash = hash & hash
}
return hash
}
@arnorhs
arnorhs / bookmarklet-compressed.js
Created March 13, 2011 15:43
From a blog post on how to create a bookmarklet using jQuery
var i,s,sc=['http://yourhostname.com/path/to/your/script.js'];if(!jQuery){sc.unshift('http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js');}for(i=0;i<sc.length;i++){s=document.createElement('script');s.src=sc[i];document.body.appendChild(s);}void(0);