Skip to content

Instantly share code, notes, and snippets.

View tranvansang's full-sized avatar
🏠
Working from home

Sang Tran tranvansang

🏠
Working from home
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active May 5, 2024 20:24
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@HarshithaKP
HarshithaKP / SessionPersistence.js
Last active February 12, 2022 09:19
Demonstration of how user session can be persisted across redirects, with an express server and request client.
var express = require('express')
var session = require('express-session')
var app = express()
var r = require('request')
// By default cookies are disabled, switch it on
var request = r.defaults( { jar:true } )
app.use(session({ secret: 'keyboard cat',saveUninitialized : false, resave : false, cookie: { maxAge: 60000 }}))
@sbusch
sbusch / _HOWTO produce namespaced ant-design CSS.md
Last active May 9, 2022 05:34
Prefix all rules of a CSS file with custom class (= create a namespace), required for antd (Ant Design)

How to produce a reliable ant-design CSS with all rules prefixed ("namespaced")

I wrote this to add a prefix to all antd style rules (or any other external CSS files). It is far from perfect, but works surprisingly well at least for my needs ;-)

Thanks to @dbtedman for making this possible with his fine PostCSS postcss-prefixwrap plugin.

Prerequisites:

  1. make sure Gulp is installed (yarn global add gulp-cli, the required gulp package is included in package.json)
  2. adapt variables at top of gulpfile.js to your needs
@timvieira
timvieira / simple-backprop.py
Last active May 14, 2022 04:32
Simple example of manually performing "automatic" differentiation.
"""
Simple example of manually performing "automatic" differentiation
"""
import numpy as np
from numpy import exp, sin, cos
def f(x, with_grad=False):
# Need to cache intermediates from forward pass (might not use all of them).
a = exp(x)
@nybblr
nybblr / 1-easy.js
Last active July 13, 2022 03:40
3 examples of using Async Generators and Async Iteration in JavaScript!
// Create a Promise that resolves after ms time
var timer = function(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Repeatedly generate a number starting
// from 0 after a random amount of time
var source = async function*() {
@katowulf
katowulf / firebase.json
Created July 11, 2016 19:37
Sample deploy config for Angular 2 routing with Firebase as found here https://github.com/katowulf/ngphx2016
{
"hosting": {
"public": "dist",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
@darcyliu
darcyliu / install_spark_centos7.sh
Created April 1, 2016 09:40
Install Spark on CentOS 7
#!/bin/bash
# Install Spark on CentOS 7
yum install java -y
java -version
yum install wget -y
wget http://downloads.typesafe.com/scala/2.11.7/scala-2.11.7.tgz
tar xvf scala-2.11.7.tgz
sudo mv scala-2.11.7 /usr/lib
sudo ln -s /usr/lib/scala-2.11.7 /usr/lib/scala
@BretFisher
BretFisher / .travis.yml
Created February 15, 2016 21:26
Travis-CI Docker Image Build and Push to AWS ECR
sudo: required #is required to use docker service in travis
language: php #can be any language, just php for example
services:
- docker # required, but travis uses older version of docker :(
install:
- echo "install nothing!" # put your normal pre-testing installs here
@bpholt
bpholt / deregister.sh
Created November 4, 2015 22:14
Stop tasks on ECS Container Instance and Deregister it from ECS Cluster
#!/bin/bash
cluster=default
container_instance= # container instance guid
tasks=$(aws --region us-west-2 ecs list-tasks --container-instance $container_instance --cluster $cluster | jq -r '.taskArns | map(.[40:]) | reduce .[] as $item (""; . + $item + " ")')
for task in $tasks; do
aws --region us-west-2 ecs stop-task --task $task --cluster $cluster
done
aws --region us-west-2 ecs deregister-container-instance --cluster $cluster --container-instance $container_instance
@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 05:08
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent