Skip to content

Instantly share code, notes, and snippets.

View elycruz's full-sized avatar

Ely De La Cruz elycruz

View GitHub Profile
@pinkhominid
pinkhominid / closestElementComposed.js
Created December 6, 2020 03:35
Element.closest() across shadow DOM boundaries
// https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
export function closestElementComposed(selector, base = this) {
function __closestFrom(el) {
if (!el || el === document || el === window) return null;
let found = el.closest(selector);
return found ? found : __closestFrom(el.getRootNode().host);
}
return __closestFrom(base);
}
@danielbachhuber
danielbachhuber / wordpress-language-codes.csv
Created April 24, 2020 12:35
Language / locale codes used in WordPress
language english_name native_name
af Afrikaans Afrikaans
ar Arabic العربية
ary Moroccan Arabic العربية المغربية
as Assamese অসমীয়া
az Azerbaijani Azərbaycan dili
azb South Azerbaijani گؤنئی آذربایجان
bel Belarusian Беларуская мова
bg_BG Bulgarian Български
bn_BD Bengali (Bangladesh) বাংলা
@armanozak
armanozak / deep-boolean.ts
Created January 1, 2020 21:03
[Callable Constructors in TypeScript] How to Merge Ambient Class Declaration with Function Declaration #typescript #tips
// requires TypeScript v3.6+
export { DeepBoolean };
type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
declare class DeepBoolean<T = any> {
constructor(source: T);
@cevek
cevek / result.js
Last active December 15, 2020 05:22
Typescript pre transformer
"use strict";
function Bar(props) { return null; }
React.createElement(Bar, { sdf: true, id: 'hello' });
React.createElement("div", { id: 'hi' }, "abc");
React.createElement("div", null, "abc");
package main
import (
"fmt"
"log"
"net/http"
)
func init() {
log.SetFlags(log.Lshortfile)
@ds300
ds300 / yarn-flat-auto.js
Created June 28, 2017 11:45
Automatically choose the latest versions of all packages when running yarn --flat
#!/usr/bin/env node
# run this before using: yarn add --dev node-pty semver
const os = require("os")
const pty = require("node-pty")
const semver = require("semver")
function semverComparator(a, b) {
if (semver.lt(a, b)) {
@disintegrator
disintegrator / wdio.conf.js
Created June 9, 2017 04:13
Run Chrome Headless with WebdriverIO and selenium-standalone
exports.config = {
capabilities: [
{
browserName: 'chrome',
chromeOptions: {
args: ['headless', 'disable-gpu'],
},
},
],
services: ['selenium-standalone'],
/**
* Created by elydelacruz on 11/8/16.
* Simple function to extract delimited content from a string.
*/
'use strict';
/**
* Returns whether our content has opening and closing delimiters.
* @param content {String}
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@PGBI
PGBI / .profile
Last active November 25, 2020 20:43
`vagrant halt all` command to halt all running vagrant VMs
# To be pasted in ~/.profile
vagrant() {
if [[ $@ == "halt all" ]]; then
command vagrant global-status | grep running | colrm 8 | xargs -L 1 -t vagrant halt
else
command vagrant "$@"
fi
}