Skip to content

Instantly share code, notes, and snippets.

addStyle(sheet, location) {
const style = document.createElement("style");
style.type = `text/css`;
style.appendChild(document.createTextNode(sheet));
location.appendChild(style);
}
const csvToJson = csv => {
const response = [];
const allLines = csv.split(/\r\n|\n/);
const headers = allLines[0].split(/\t|,/).filter(value => value);
for (let item = 1; item < allLines.length; item++) {
const data = {};
const lineData = allLines[item].split(/\t|,/).filter(value => value);
if (lineData.length == headers.length)
lineData.forEach((line, index) => {
data[headers[index]] = line;
import { HTML } from "/modules/light-html/index.js";
class Component extends HTMLElement {
constructor() {
super();
this.hide = this.hide.bind(this);
}
hide() {
this.style.display = "none";
sudo apt-get install postgresql-server-dev-all
sudo apt-get install postgresql-common
use svg <svg class="twitter-icon">
<use xlink:href="path/to/icons.svg#twitter-icon"></use>
<svg>
@tonis2
tonis2 / gist:3b07ea8b0a1f30d0e30c3a0bb4112349
Last active June 8, 2018 12:48
rust rock, scissors, papers.
extern crate rand;
use rand::prelude::*;
use std::collections::HashMap;
use std::io::{stdin, stdout, Write};
fn main() {
let mut game_values: HashMap<&str, i32> = HashMap::new();
game_values.insert("kivi", 1);
@tonis2
tonis2 / gist:d67c91bd69e389dccc9556266910d199
Created June 15, 2018 22:06
Rust where clause example
struct Moose {
name: String
}
struct Deer {
name: String
}
trait Actions {
fn baby_name(&self) -> String;
@tonis2
tonis2 / gist:7639afe88a6b27ca4eca5223797e70b5
Created June 25, 2018 11:36
Send mail with node.js and ssmtp
const emails = "[email protected]"
const msg = `<p><span>msg:${req.body.msg}</span> <br /> <span>url:${req.body.url}</span> <br /> <span>line:${req.body.lineNo}</span> <br /> <span>column:${req.body.columnNo}</span> <br /> error:${req.body.error}</p>`;
exec.exec(`echo "From:[email protected]\r\nDate: $(date)\r\nSubject:website crash report\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n ${msg}" | sudo ssmtp -vvv -C ssmpt2.conf -ap 55604881 -F " Pro error" ${emails}`, (err, stdout, stderr) => {
if (err) {return;}
});
@tonis2
tonis2 / gist:9f87420a12e409009761a45b5787e156
Created July 4, 2018 12:00
UPLOAD to FIREBASE storage with REST API
### Add security rule for public access
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
@tonis2
tonis2 / gist:43d8003a9237adbb4adad68d46202240
Last active September 29, 2018 08:48
Regex exercise interview question
/*
write a function that takes two inputs:
 vocabulary - array of strings (words)
 sentence - string
and returns:
 true - if the sentence can be split in the words given; words can be repeated, words can have any order; you can use only subset of words
 false - if the sentence cannot be split in the words