Skip to content

Instantly share code, notes, and snippets.

View d4rekanguok's full-sized avatar
💭
I may be slow to respond.

Derek Nguyen d4rekanguok

💭
I may be slow to respond.
  • Pen & Pillow
  • Seoul, SK
View GitHub Profile
@JulienPradet
JulienPradet / Component.svelte
Last active November 25, 2023 11:16
How to use `use` directive to trap focus in Svelte
<script>
import {trapFocus} from "./trapFocus";
</script>
<div use:trapFocus>
<button>Hi!</button>
<button>Second button</button>
</div>
@aleclarson
aleclarson / rollup-typescript.md
Last active February 27, 2024 09:15
The best Rollup config for TypeScript libraries

Features

🔥 Blazing fast builds
😇 CommonJS bundle
🌲 .mjs bundle
.d.ts bundle + type-checking
🧐 Source maps

Install

type Listener<T> = (val: T) => void;
type Unsubscriber = () => void;
export class Observable<T> {
private _listeners: Listener<T>[] = [];
constructor(private _val: T) {}
get(): T {
return this._val;
@ernsheong
ernsheong / access-mac-localhost-from-parallels-desktop-ie-edge.md
Last active January 24, 2024 00:30
Accessing macOS localhost from Parallels Desktop IE or Edge

Access macOS localhost from IE or Edge within Parallels Desktop

This issue is so infuriating that I'm going to take some time to write about it.

  1. MOST IMPORTANT. Your local development server must be bound to IP address 0.0.0.0. Some do this by default, but many don't. You need to make sure that you run your local server with correct IP bindings. You may need to provide additional flags to your serve commands e.g. polymer serve --hostname domain.local, hugo serve --bind 0.0.0.0. If you use a named domain like domain.local, it has to be defined in /etc/hosts and pointing at 0.0.0.0.

  2. My Parallels setting is using Shared Network, nothing special there.

  3. Open macOS Terminal and type ifconfig. Look for the value under vnic0 > inet. It is typically 10.211.55.2.

@dustinsenos
dustinsenos / rename-text-layers.js
Last active February 1, 2019 08:29
A simple sketch plugin to rename the selected layers to match the contents of their text.
var sketch = context.api()
var MAX_CHARS = 60
var document = sketch.selectedDocument
var selection = document.selectedLayers
var renamedTextLayers = false
selection.iterate(function(item) {
if (!item.isText) {
return
@anvk
anvk / promises_reduce.js
Last active October 11, 2023 09:02
Sequential execution of Promises using reduce()
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
let final = [];
function workMyCollection(arr) {
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@jamestalmage
jamestalmage / How_Require_Extensions_Work.md
Last active February 28, 2024 18:22
Breakdown of How Require Extensions Work

Why

Doing require extensions correctly is essential, because:

  1. Users should be able to install multiple extensions in succession, and have them work together.
  2. Coverage tools like nyc need it to reliably supply coverage information that takes into account sourcemaps from upstream transforms.
  3. Because non-standard, un-predictable behavior causes hard to solve bugs, and major headaches for project maintainers.

What is a require extension anyways?

var doc = context.document
var selectLayersOfType_inContainer = function(layerType, containerLayer) {
// Filter layers using NSPredicate
var scope = (typeof containerLayer !== 'undefined') ? [containerLayer children] : [[doc currentPage] children],
predicate = NSPredicate.predicateWithFormat("(className == %@)", layerType),
layers = [scope filteredArrayUsingPredicate:predicate];
// Deselect current selection
@abynim
abynim / Sketch Plugin Snippet - Managing Files.js
Last active October 16, 2020 20:32
Sketch Plugin functions for working with files.
var writeTextToFile = function(text, filePath) {
var t = [NSString stringWithFormat:@"%@", text],
f = [NSString stringWithFormat:@"%@", filePath];
return [t writeToFile:f atomically:true encoding:NSUTF8StringEncoding error:nil];
}
var readTextFromFile = function(filePath) {
var fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:filePath]) {
return [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];