Skip to content

Instantly share code, notes, and snippets.

View tonis2's full-sized avatar
🐼

Tonis tonis2

🐼
View GitHub Profile
@tonis2
tonis2 / gist:1f7f87b34c4850b8b4bb0009c5f21d94
Created January 30, 2018 10:12
Convert string to HTML
String.prototype.html = function() {
let parser = new DOMParser();
let doc = parser.parseFromString(this, "text/html");
return doc.body.firstChild;
};
class Component extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
const height = this.clientHeight,
width = this.clientWidth;
this.createSvg();
@tonis2
tonis2 / gist:c0d628d277348aa3f2bafeb02a4ad920
Created September 3, 2017 13:25
remove stupid ubuntu error
sudo dpkg -i --force-overwrite /var/cache/apt/archives/libgl1-mesa-glx_1%3a17.3~git170828152300.63e79a8~z~padoka0_amd64.deb
@tonis2
tonis2 / gist:49e5b1f4d94ba8e055c228d7688fd97d
Created August 31, 2017 15:18
Select three.js object with mouse
selectObject(event) {
event.preventDefault();
let vector = new THREE.Vector3(
event.clientX / window.innerWidth * 2 - 1,
-(event.clientY / window.innerHeight) * 2 + 1,
0.5
);
vector = vector.unproject(this.camera);
const raycaster = new THREE.Raycaster(
@tonis2
tonis2 / plant.gltf
Last active July 7, 2017 14:24
plant.gltf
{
"accessors": {
"accessors_0": {
"bufferView": "bufferViews_3",
"byteOffset": 0,
"byteStride": 2,
"componentType": 5123,
"count": 855,
"max": [
246
@tonis2
tonis2 / index.html
Created March 5, 2017 12:50 — forked from tmichel/index.html
simple websocket example with golang
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<div>
<form>
<label for="numberfield">Number</label>
<input type="text" id="numberfield" placeholder="12"/><br />
@tonis2
tonis2 / convert_features_opencv_traincascade.py
Created December 26, 2016 19:47 — forked from mtschirs/convert_features_opencv_traincascade.py
Converting the new OpenCV haar cascades into the js-objectdetect format.
import xml.etree.ElementTree
'''
Classifier - array layout:
[width, height, threshold, num_simple_classifiers, tilted, num_features, f1, f2, f3, f4, f_weight, simple_threshold, left_val, right, val, ...]
'''
wrapper = "(function(module) {\n" + \
" \"use strict\";\n" + \
" \n" + \
@tonis2
tonis2 / gist:8b68e4034f22d619dc39a1f91b47fbdb
Last active October 23, 2016 17:32
mutate rust struct
#![allow(dead_code)]
struct Car {
name: String,
seats: i32,
speed: i32,
}
impl Car {
fn drive(&self) {
println!("{name} drives at speed: {speed} km/h", speed = self.speed, name = self.name);
@tonis2
tonis2 / gist:071e662ac50e809775e44ce93c1d426b
Created October 11, 2016 15:51
remove duplicates from array
const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
const count = names =>
names.reduce((a, b) =>
Object.assign(a, {[b]: (a[b] || 0) + 1}), {})
const duplicates = dict =>
Object.keys(dict).filter((a) => dict[a] > 1)
console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
server {
listen 443 ssl;
server_name url.pw www.url.pw;
ssl_certificate /etc/letsencrypt/live/scarystories.pw/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/scarystories.pw/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;