Skip to content

Instantly share code, notes, and snippets.

@tnhu
tnhu / MyContext.tsx
Created November 24, 2021 23:30
Six simple steps to create and use React Context #react #typescript #context
import React, { useState, useContext } from 'react'
// 1. Define data that the context holds, plus a setter to update data
interface MyContextProps {
standalone: boolean
setMyContext: (value: Partial<Omit<MyContextProps, 'setMyContext'>>) => void
}
// 2. Create the actual context with some default data
const MyAppContext = React.createContext<MyContextProps>({
@tnhu
tnhu / web-servers.md
Last active March 23, 2020 20:33 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8181
@tnhu
tnhu / curl.md
Created August 30, 2018 00:13 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@tnhu
tnhu / icons.css
Created October 19, 2017 18:16
icons.css
:root {
--icon-pending: url('data:image/svg+xml;utf8,<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="SUCCESS_1_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd;fill:%23DBDCDD;} .st1{fill-rule:evenodd;clip-rule:evenodd;fill:%23FFFFFF;} </style> <g id="Ellipse_524"> <g> <circle class="st0" cx="8" cy="8" r="8"/> </g> </g> <g id="Ellipse_1551"> <g> <circle class="st1" cx="8" cy="8" r="6"/> </g> </g> </svg>');
--icon-queued: url('data:image/svg+xml;utf8,<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="QUE_1_copy_1_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"> <style type="text/css"> .st0{fill:#E1E4E5;} .st1{fill:#FFFFFF;} .st2{fill:#C3C8CA;} </style> <g id="Ellipse_
@tnhu
tnhu / gist:4569211a3f1c6758ba22e7281aa739b3
Created January 12, 2017 00:48
Sublime regular expression search & replace
Find what: (^.*): (.*$)
Replace with: "$1": "$2",
--
Before:
memberOf: CN=Realtime Systems,OU=DEPT,OU=Groups,DC=corp,DC=qc
department: Inventory & DMP
After:
@tnhu
tnhu / postgres-cheatsheet.md
Created December 16, 2016 02:19 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@tnhu
tnhu / DumpStack.java
Created July 13, 2016 22:41
Dump Java stack trace without throwing an exception
import org.apache.commons.lang3.exception.ExceptionUtils;
import play.Logger;
String stackTrace = ExceptionUtils.getStackTrace(new Exception()));
// Log warning with stack trace for a deprecated method
Logger.warn("Method is deprecated: " + stackTrace);
@tnhu
tnhu / fetch2.js
Created June 2, 2016 04:05
fetch2
/*
fetch() only rejects when network error occurs (offline), fetch2() rejects all non-200 statuses
*/
const fetch2 = api => fetch(api).then(res => res.ok ? res : Promise.reject(res));
@tnhu
tnhu / excel_generator.py
Created April 22, 2016 20:38
Open and Edit an Excel template using Python's openpyxl library
from openpyxl import load_workbook
wb = load_workbook('template.xlsx')
# grab the active worksheet
ws = wb.active
# Data can be assigned directly to cells
ws['A2'] = 'Tom'
ws['B2'] = 30
@tnhu
tnhu / visor-archivos-online.md
Last active December 10, 2018 12:15 — forked from izazueta/visor-archivos-online.md
Google Docs Viewer & Office Web Apps Viewer