Skip to content

Instantly share code, notes, and snippets.

@lilywang711
lilywang711 / useImperativeHandle.tsx
Created July 30, 2020 06:47
useImperativeHandle in typescript
// 定义
export interface MyInputHandles {
focus(): void;
}
const MyInput: RefForwardingComponent<MyInputHandles, MyInputProps> = (
props,
ref
) => {
const inputRef = useRef<HTMLInputElement>(null);
@wmayner
wmayner / color_swatch_notebook_cell.py
Last active July 17, 2023 01:00
Display a color swatch from hex color strings with IPython in a Jupyter Notebook
from IPython.display import Markdown, display
colors = ['#018700', '#00acc6', '#e6a500']
display(Markdown('<br>'.join(
f'<span style="font-family: monospace">{color} <span style="color: {color}">████████</span></span>'
for color in colors
)))
@bvaughn
bvaughn / index.md
Last active June 16, 2024 21:50
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.

var convertToString = function(array) {
return array.map((item, index) => '"' + index + ' ' + item.replace(/"/g, '') + '"').join('');
}
var find = function(needle, sourceAsString, source) {
var rx = new RegExp('"(\\d+) ([^"]*' + needle + '[^"]*)"','gi');
var i = 0, results = [];
while (result = rx.exec(sourceAsString)) {
results.push(result[1]);
if (results.length >= 100) {
@dlmanning
dlmanning / hoverable-hoc.js
Created November 7, 2015 19:07
Simple higher-order React component to make a compoent react to hover events.
function hoverable (WrappedComponent, propName = 'hover') {
return class HoverableComponent extends Component {
constructor (props) {
super(props)
this.state = { hovered: false }
}
turnHoverOn () {
this.setState({ hovered: true })
@jhnns
jhnns / git-pr
Last active March 15, 2021 07:50
Git custom command to quickly checkout pull-requests from different origins as described in https://help.github.com/articles/checking-out-pull-requests-locally. Place this file somewhere in your path and git will run it everytime you type `git pr ...`
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: git pr [clean] [<remote>] <id-or-url>"
echo ""
echo "Examples:"
echo "git pr 42 --> git fetch origin pull/42/head:pr/origin/42"
echo "git pr upstream 42 --> git fetch upstream pull/42/head:pr/upstream/42"
echo "git pr https://github.com/peerigon/phridge/pull/1 --> git fetch https://github.com/peerigon/phridge.git pull/1/head:pr/peerigon/phridge/1"
echo "git pr clean --> Deletes all branches that match pr/*/* and pr/*/*/*"
@iMilnb
iMilnb / snsread.py
Created August 2, 2015 20:20
Basic Flask snippet to handle AWS SNS messages and subscription
from flask import Flask, request
import requests
import json
app = Flask(__name__)
def msg_process(msg, tstamp):
js = json.loads(msg)
msg = 'Region: {0} / Alarm: {1}'.format(
js['Region'], js['AlarmName']
@rjattrill
rjattrill / multiline-values.yaml
Created November 18, 2013 06:33
Break YAML over multiple lines
# Join multiple lines without new line
value: >
part 1
part 2
# Join with newline
value2: |
line 1
line 2
@mdaniel
mdaniel / Vagrantfile
Last active February 21, 2021 10:30
Provision a virtual machine for building ChromeOS using Vagrant <http://www.vagrantup.com>. Just download this into a directory, name it ``Vagrantfile`` (if it isn't already), run ``vagrant up`` followed by ``vagrant ssh`` and you'll see two shell scripts there, ready to sync up the ChromeOS source code.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu1204_64"