Skip to content

Instantly share code, notes, and snippets.

View jeongsd's full-sized avatar
🎯
Focusing

Jeong Seong Dae jeongsd

🎯
Focusing
View GitHub Profile
@Schniz
Schniz / async-route.js
Last active August 25, 2016 05:11
Async react router component for using webpack chunks like Instagram guys do. work in progress.
/** @jsx React.DOM */
var React = require('react');
var handlers = {};
var AsyncRoute = function(req) {
return React.createClass({
getInitialState: function() {
return {
myComponent: handlers[req]
@theprojectsomething
theprojectsomething / Timer.js
Created March 17, 2014 07:26
Timer - a simple JS timing implementation utilising requestAnimationFrame.
/*
Timer
- utilises animation frames (with a fallback to setTimeout when using the polyfill, below)
- returns remaining (or running) time
- pass a callback [fn], with an optional duration [ms] and autotart [bool], to the constructor or 'init' method
eg. new Timer(foo, 1000) *or* (new Timer()).init(foo, 0, true)
- for uniform x-browser support combine with the requestAnimationFrame polyfill from Erik Möller, et. al.
[https://github.com/darius/requestAnimationFrame]
*/
@benplum
benplum / matchMedia - IE9
Last active April 16, 2020 15:57
matchMedia Polyfill w/ Listeners - IE9
// Modernizr style test
if (!(window.webkitMatchMedia || window.mozMatchMedia || window.oMatchMedia || window.msMatchMedia || window.matchMedia)) {
var root = document.getElementsByTagName( 'html' )[0];
root.className += ' no-matchmedia';
}
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */
window.matchMedia || (window.matchMedia = function() {
"use strict";
@jacob-beltran
jacob-beltran / requestAnimationFrame.js
Last active April 17, 2020 04:05
React Performance: requestAnimationFrame Example
// How to ensure that our animation loop ends on component unount
componentDidMount() {
this.startLoop();
}
componentWillUnmount() {
this.stopLoop();
}
@mhaagens
mhaagens / authentication_middleware.js
Last active April 22, 2020 10:14
Auth middleware
import jwt from "jsonwebtoken";
import User from "@server/models/user_model";
const PRODUCTION = process.env.NODE_ENV === "production";
export default (options) => async (req, res, next) => {
const refreshToken = req.cookies["refresh_token"];
const accessToken = req.cookies["access_token"];
const csrfHeader = req.get("X-Csrf-Token");
@chodorowicz
chodorowicz / toggle.js
Last active February 15, 2021 21:23
lodash toggle array element
/**
* descructive
* https://github.com/lodash/lodash/issues/1677
*/
function toggle(collection, item) {
var idx = _.indexOf(collection, item);
if(idx !== -1) {
collection.splice(idx, 1);
} else {
collection.push(item);
@mape
mape / apmPatchPrisma.ts
Last active October 20, 2021 20:26
Elastic APM node client instrumenting Prisma 2 queries
import { condensePrismaQuery } from './utils';
// Screenshot of a trace sample: https://i.imgur.com/XuhuQFq.png
// Service: https://www.elastic.co/apm
// Node module: https://github.com/elastic/apm-agent-nodejs
// Prisma: https://www.prisma.io/
// Using "@prisma/client": "dev"
// Thanks to https://github.com/prisma/prisma/pull/2902
@hsablonniere
hsablonniere / EXPLAINER.md
Last active November 15, 2021 21:19
Explainer for my rollup plugin idea about import.meta.url with assets

Explainer for my rollup plugin idea

The "i-prefer-import-meta-url-over-using-esm-import-to-get-a-relative-file-url" plugin ;-)

Context

In my components library, I have SVG images. I used them with <img> tags in my components and to get the proper relative URL, I use new URL('../assets/image.svg', import.meta.url').href.

To make this work in a rollup build, you need to:

@rodleviton
rodleviton / imagemagick-install-steps
Created May 26, 2014 07:37
Installing Image Magick on Ubuntu 14.04
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick-6.8.7-7.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
@sturmenta
sturmenta / firestore2json.js
Last active October 28, 2022 19:03
firestore to json & json to firestore
const admin = require('firebase-admin');
const fs = require('fs');
const serviceAccount = require('../../../../../../Private/myschool-data_transfer-key.json');
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
const schema = require('./schema').schema;
const firestore2json = (db, schema, current) => {