Skip to content

Instantly share code, notes, and snippets.

View typable's full-sized avatar
🛠️
building stuff

Andreas typable

🛠️
building stuff
View GitHub Profile
@typable
typable / linkedlist.go
Last active April 28, 2021 15:19
LinkedList - Go
package main
type Node struct {
val int
ref *Node
}
type Linkedlist struct {
list *Node
}
@typable
typable / common.js
Last active April 28, 2021 15:20
JavaScript Cheat Sheet
// sigmoid function
(x) => 1 / (1 + Math.pow(Math.E, -k * (x - b)));
// parable function
(x) => a * Math.pow(x - b, 2) + c;
// range function
// returns array with numbers from 0 to n
(n) => [...Array(n).keys()];
@typable
typable / Images.java
Last active April 28, 2021 15:21
Image Scaling
public static BufferedImage scaleByWidth(BufferedImage sourceImage, int targetWidth) {
double factor = (double) targetWidth / (double) sourceImage.getWidth();
int targetHeight = (int) (sourceImage.getHeight() * factor);
return scale(sourceImage, targetWidth, targetHeight);
}
public static BufferedImage scaleByHeight(BufferedImage sourceImage, int targetHeight) {
@typable
typable / navigate.js
Last active April 28, 2021 15:21
Canvas Mouse Dragging
// state
state = {
origin: { x: 0, y: 0 },
move: { x: 0, y: 0 },
scale: 1,
delta: 0.5,
dragging: false,
min: 1,
max: 100
};
@typable
typable / gamepad.js
Last active April 28, 2021 15:22
Detect Gamepad input
const KEY_BINDING = {
0: 'A',
1: 'B',
2: 'X',
3: 'Y',
4: 'L1',
5: 'R1',
6: 'L2',
7: 'R2',
8: 'Option',
@typable
typable / openstreetmap.md
Last active April 28, 2021 15:23
Leaflet OSM

OpenStreetMap API

A Leaflet JS implementation to provide Map-Views based on OSM (OpenStreetMap).
Leaflet Docs

Leaflet CDN:

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css">
<script type="text/javascript" src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"></script>
@typable
typable / browser.js
Last active April 28, 2021 15:27
Browser Detection
var Browser = {
type: null,
version: null,
support: function(obj) {
return obj != undefined;
},
is: function(type, version) {
if(type !== Browser.type) {
return false;
}
@typable
typable / dns.js
Last active April 28, 2021 15:27
Update Domain IP
import request from './request.js';
const EXTERNAL_IP_SERVICE_URL = 'http://checkip.amazonaws.com';
const DOMAIN_IP_SERVICE_URL = 'https://dns.google.com/resolve';
const DOMAIN_PROVIDER_SERVICE_URL = 'https://dynamicdns.park-your-domain.com';
async function resolve(domain) {
if(typeof domain === 'undefined' || domain.length == 0) {
throw 'Invalid domain argument!';
}

SublimeText for ChromeOS

Installation

sudo su
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | apt-key add -
apt-get install apt-transport-https
echo "deb https://download.sublimetext.com/ apt/stable/" | tee /etc/apt/sources.list.d/sublime-text.list
apt-get update
@typable
typable / terminal-noise.js
Last active November 5, 2021 13:16
Terminal 2D Noise
function base(n) {
return Math.pow(2, n) + 1;
}
function find(x, n) {
let b = 2;
let i = 0;
while(x > b) {
b = base(i + 1);
i++;