Skip to content

Instantly share code, notes, and snippets.

limichange limichange

Block or report user

Report or block limichange

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@morajabi
morajabi / useRect.js
Created Feb 18, 2019
useRect — getBoundingClientRect() React Hook with resize handler
View useRect.js
import { useLayoutEffect, useCallback, useState } from 'react'
export const useRect = (ref) => {
const [rect, setRect] = useState(getRect(ref ? ref.current : null))
const handleResize = useCallback(() => {
if (!ref.current) {
return
}
@luyilin
luyilin / jsonFormatHighlight.js
Last active Feb 12, 2018
json format && highlight
View jsonFormatHighlight.js
// Format json and highlight it as well.
// Now you can use the package https://github.com/luyilin/json-format-highlight directly! :D
// default colors of key and types of value
const defaultColors = {
keyColor: 'dimgray',
numberColor: 'lightskyblue',
stringColor: 'lightcoral',
trueColor: 'lightseagreen',
falseColor: '#f66578',
@zh-h
zh-h / who-weibo.js
Last active Feb 12, 2019
是谁发的微博微博图片
View who-weibo.js
function decodeBase62(number) {
var alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
var out = 0
var len = number.length - 1
for (var t = 0; t <= len; t++) {
out = out + alphabet.indexOf(number.substr(t, 1)) * Math.pow(62, len - t)
}
return out
}
@praveenpuglia
praveenpuglia / shadow-dom.md
Last active Mar 28, 2020
Everything you need to know about Shadow DOM
View shadow-dom.md

I am moving this gist to a github repo so more people can contribute to it. Also, it makes it easier for me to version control.

Please go to - https://github.com/praveenpuglia/shadow-dom-in-depth for latest version of this document. Also, if you find the document useful, please shower your love, go ⭐️ it. :)

Shadow DOM

Heads Up! It's all about the V1 Spec.

In a nutshell, Shadow DOM enables local scoping for HTML & CSS.

@egoist
egoist / list.md
Last active Mar 3, 2017
The software used by @egoist
View list.md
@ChrisChares
ChrisChares / AsyncAwaitGenerator.md
Last active Jul 9, 2019
async/await with ES6 Generators & Promises
View AsyncAwaitGenerator.md

async/await with ES6 Generators & Promises

This vanilla ES6 function async allows code to yield (i.e. await) the asynchronous result of any Promise within. The usage is almost identical to ES7's async/await keywords.

async/await control flow is promising because it allows the programmer to reason linearly about complex asynchronous code. It also has the benefit of unifying traditionally disparate synchronous and asynchronous error handling code into one try/catch block.

This is expository code for the purpose of learning ES6. It is not 100% robust. If you want to use this style of code in the real world you might want to explore a well-tested library like co, task.js or use async/await with Babel. Also take a look at the official async/await draft section on desugaring.

Compatibility

  • node.js - 4.3.2+ (maybe earlier with
@barnabas-szekeres
barnabas-szekeres / counter-component.js
Last active Feb 18, 2017
Store states in sessionstorage
View counter-component.js
//Component
import Counter from '../store/counter';
export default {
data() {
return {
};
},
computed: {
counter() {
@jish
jish / promise.js
Created Oct 28, 2014
An example "always" behavior for ES6 promises. This only works if you do not create / return intermediate promises.
View promise.js
// A thing I want to do
// This flow only involves **one** promise, for example an ajax call
// None of the subsequent `then` or `catch` calls, return new promises.
var explode = false;
var promise = new Promise(function(resolve, reject) {
if (explode) {
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active Apr 6, 2020
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew
View fix-homebrew-npm.md

READ THIS Very Important Update

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

You can’t perform that action at this time.