Skip to content

Instantly share code, notes, and snippets.

View lauri-kaariainen's full-sized avatar

Lauri Kääriäinen lauri-kaariainen

View GitHub Profile
@lauri-kaariainen
lauri-kaariainen / gist:8089926
Created December 23, 2013 00:05
Array with morse-code as keys (in javascript).
var abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var morsecode =[
'.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....',
'..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.',
'--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-',
'-.--', '--..'
];
var morseArray = new Array();
var length = abc.length;
for(var i = 0;i < length;i++){
@lauri-kaariainen
lauri-kaariainen / gist:8093387
Created December 23, 2013 08:18
Parsing xml namespaces with jquery 1.10.x ( ie. <something:expirationTime )
this.getElementsByTagNameNS("*", "expirationTime")
@lauri-kaariainen
lauri-kaariainen / sortMixedArray
Created April 6, 2014 12:06
Javascript sort function for some mixed type (string, number, undefined) arrays
function simpleAnalyze(a,b){
if(a === "" && b !== "")
return -1;
if(a !== "" && b === "")
return 1;
if(a == b)
return 0;
return "";
}
@lauri-kaariainen
lauri-kaariainen / index.html
Last active August 29, 2015 14:09
ProJ4.js coordinate changes from ETRS-TM35FIN to WGS-84
<!doctype html>
<head>
<meta charset="utf-8">
<script src="proj4.js"></script>
</head>
<body>
<script>
//https://github.com/proj4js
@lauri-kaariainen
lauri-kaariainen / lierolibre-emscripten env vars
Created January 13, 2015 14:51
lierolibre compiling with emconfigure (emscripten) . The required environment variables in Ubuntu14.04:
1st and 2nd: pkg-config --libs libconfig++
3rd and 4th: pkg-config --libs zlib
copy from here:
export LIBCONFIGXX_CFLAGS=-lconfig++
export LIBCONFIGXX_LIBS=-lconfig++
export ZLIB_CFLAGS=-lz
export ZLIB_LIBS=-lz
@lauri-kaariainen
lauri-kaariainen / backend
Created May 9, 2015 07:51
Huuto.net category and item API usage with simple PHP code
<?php
//CALLHUUTO AND ID!
if(isset($_GET['callHuuto']) && isset($_GET['id'])) {
$doc = new DOMDocument();
//error_log('http://api.huuto.net/somt/0.9/items/'.$_GET['id']);
$doc->load('http://api.huuto.net/somt/0.9/items/'.$_GET['id']);
echo $doc->saveXML();
die();
@lauri-kaariainen
lauri-kaariainen / color-conversion-algorithms.js
Last active May 27, 2018 13:41 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
function betterRgbToHsl(r, g, b) {
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0; // achromatic
} else {
@lauri-kaariainen
lauri-kaariainen / RunInConsole.js
Last active March 8, 2020 22:59
scrape links on page from developer console, calls separated by 1000ms
var hrefs =
Array.from(document.querySelectorAll("a"))
.map(link=>link.href)
.sort()
.filter((el,i,arr)=>!arr.slice(i+1).includes(el))
.filter(href=>href.match(/ads\/\d/))
.filter((_,i,arr)=>i ? (console.log(arr.length),true):true)
.filter(href=>(console.log(href),true)).slice(0);
window.array = [];
hrefs.forEach((href,i)=>
@lauri-kaariainen
lauri-kaariainen / alkoaddresses.json
Last active April 26, 2020 12:01
street addresses and coordinates for Alko in Finland in JSON, Alkojen katuosoitteet ja koordinaatit JSON
[
{
"name": "Alko Akaa Toijala",
"address": "Valtatie 1, 37800 TOIJALA",
"lat": "61.16822725",
"lon": "23.8673481114683"
},
{
"name": "Alko Alajärvi",
"address": "Yrittäjäntie 5, 62900 ALAJÄRVI",
const seatIds =
getInput()
.replace(/[BR]/g,"1")
.replace(/[FL]/g,"0")
.split("\n")
.map(line=>line.trim())
.map(line=>({row:parseInt(line.slice(0,7),2),column:parseInt(line.slice(7),2)}))
.map(obj=>({...obj,seatId:obj.row*8+obj.column}))
.map(e=>e.seatId)
//A: