Skip to content

Instantly share code, notes, and snippets.

function decorate(tag, template) {
customElements.define(tag, class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
let root = this.shadowRoot;
if(!root.firstChild) {
@tomcon
tomcon / magnolia-js-2019-wc-svelte-links.md
Created April 20, 2019 16:10 — forked from natec425/magnolia-js-2019-wc-svelte-links.md
Magnolia JS 2019 - Web Components & Svelte workshop links
@tomcon
tomcon / package.json
Created April 5, 2019 15:26 — forked from adamreisnz/package.json
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Buczynski",
"url": "http://adambuczynski.com"
},
"license": "UNLICENSED",
@tomcon
tomcon / async.js
Created March 9, 2019 17:22 — forked from Acesmndr/async.js
AJAX with callbacks and promises
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; // importing xmlhttprequest package because node doesn't support it out of the box
const superHeroes = ['Batman', 'Superman', 'WonderWoman', 'Flash', 'Cyborg', 'Aquaman', 'Green Lantern', 'Martian Manhunter']; // an array of request params
const completedFetchingData = () => { // function to be called when all ajax requests complete.
console.log('Just completed fetching the data');
}
const failedFetchingData = () => { // function to be called when data fetching fails
console.log('Failed to fetch the data');
}
const ajaxRequestWithPromise = (param) => {
@tomcon
tomcon / redis_cheatsheet.bash
Created March 7, 2019 12:21 — forked from LeCoupa/redis_cheatsheet.bash
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.
@tomcon
tomcon / svelte.d.ts
Created October 22, 2018 10:36
Project-wide Svelte component typings for VSCde
declare module '*.svelte' {
type Data = { [key]: any }
type Changed = { [key]: boolean }
type Listener = { cancel: () => void }
export default class Component {
root: Component
options: Data
constructor(init: { target: Element, data: Data })
@tomcon
tomcon / html-escape.md
Created October 7, 2018 12:21 — forked from WebReflection/html-escape.md
How to escape and unescape from a language to another

update

I've created a little repository that simply exposes the final utility as npm module.

It's called html-escaper


there is basically one rule only: do not ever replace one char after another if you are transforming a string into another.

@tomcon
tomcon / query.sql
Created September 30, 2018 18:05 — forked from cowboy/query.sql
postgres sql query
-- This is the result I want:
--
-- foo | bar | description
-- -----+-----+-------------
-- 3 | 4 | two
-- 1 | 2 | four
-- 5 | 6 | five
--
-- Which I can get with this query, but can I do it
-- more simply?
@tomcon
tomcon / custom-element.js
Created September 25, 2018 11:59 — forked from Rich-Harris/custom-element.js
Svelte with/without `customElement: true`
var hw = (function () {
'use strict';
function noop() {}
function assign(tar, src) {
for (var k in src) tar[k] = src[k];
return tar;
}
@tomcon
tomcon / svelte-observe.js
Created September 19, 2018 17:08 — forked from jacwright/svelte-observe.js
One `observe` for all svelte needs.
export function observe(key, callback, opts) {
const single = !Array.isArray(key);
const keypaths = single ? [ key ] : key;
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.'));
const keys = parts.map(parts => parts[0]);
const fn = callback.bind(this);
let last = parts.map(parts => getNestedValue(this.get(), parts));
if (!opts || opts.init !== false) {