Skip to content

Instantly share code, notes, and snippets.

use svg <svg class="twitter-icon">
<use xlink:href="path/to/icons.svg#twitter-icon"></use>
<svg>
sudo apt-get install postgresql-server-dev-all
sudo apt-get install postgresql-common
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";
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;
addStyle(sheet, location) {
const style = document.createElement("style");
style.type = `text/css`;
style.appendChild(document.createTextNode(sheet));
location.appendChild(style);
}
@tonis2
tonis2 / gist:324746c33d18120f54364ad652d7bde6
Created April 26, 2018 11:54
Replace data:image urls in JSON
import fs from "fs";
import uuid from "uuid/v1";
const replaceDataImg = (string) => {
const data = string.replace(/^data:image\/\w+;base64,/, "");
const buf = new Buffer(data, 'base64');
const name = `server/files/${uuid()}.png`;
fs.writeFile(name, buf, (error) => { if(error) console.log("Error!", error)});
return `"${name}"`;
}
server {
listen 80;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_proxied any;
gzip_types *;
source_charset utf-8;
@tonis2
tonis2 / gist:91c24ac8b8b9274665b22a9659d39b8d
Created April 19, 2018 08:53
contentEditable insert element and focus behind it.
const container = document.querySelector(".pell-content");
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let dom = HTML`<div id="node"><span style="color:red">${selection.toString()}</span></div>`;
selection.deleteFromDocument();
range.insertNode(dom);
///Insert first node
range.setStartAfter(dom);
range.setEndAfter(dom);
selection.removeAllRanges();
@tonis2
tonis2 / gist:0068d05ef5a7760e1bfe682cedc64fba
Created March 31, 2018 21:15
Atom HTMLelement snipper
'.source.js':
'Console log':
'prefix': 'log'
'body': 'console.log($1)',
'component':
'prefix': 'component'
'body': 'class Component extends HTMLElement { connectedCallback() {}} export default Component'
'constructor':
'prefix': 'const'
@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;
};