Instantly share code, notes, and snippets.

View reducer.ts
import { AnyAction, Reducer } from 'redux'
type UserState = Readonly<{
id: number
}>
export const initialState: UserState = {
id: -1
}
View visible.js
import React from 'react';
const visible = isVisible => Component => {
class VisibleComponent extends React.Component {
componentDidMount() {
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this));
}
componentWillUnmount() {
this.unsubscribe();
View csv.js
// Usage:
// const records = [['James', 'james@james.com'], ['Steve', 'steve@steve.com']];
// const titles = ['name', 'email'];
// generateCsv(records, titles);
// RFC 4180
// Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.
const formatValue = value => {
const chars = [',', '"', '\n'];
const mustBeEnclosed = chars.some(c => value.includes(c));
View index.js
const attempts = [
[ 1.613, 4.2010000000000005, 13.652000000000001, 7.035, 5.371, 9.951, 8.934000000000001, 5.534, 4.251, 7.636, 15.402000000000001, 6.384 ],
[ 1.401, 5.051, 11.852, 5.534, 3.384, 4.95, 6.501, 7.1850000000000005, 5.702, 5.401, 10.685, 5.867 ],
[ 1.349, 3.984, 9.401, 2.983, 4.0840000000000005, 5.05, 6.939, 5.7170000000000005, 3.517, 3.384, 9.185, 6.417 ],
];
const levels = [];
for (let i = 0; i < attempts[0].length; i++) {
View index.js
const lngRadius = 0.25;
const point = {
lat: 51.507351,
lng: -0.127758,
};
const latmin = point.lat - lngRadius;
const latmax = point.lat + lngRadius;
const lngmin = point.lng - (lngRadius / 85 * 180); // Number of units different from lng so need to calculate
View index.js
const countHoriz = 24;
// 16, 24
const width = 960;
const height = 600;
const squareSize = width / countHoriz;
const countVert = height / squareSize
View jsx-comment.sublime-snippet
<snippet>
<content><![CDATA[
{/* ${1:JSX Comment} */}
]]></content>
<!-- Hit `jc` in any JS document to get a JSX comment -->
<tabTrigger>jc</tabTrigger>
<scope>source.js</scope>
</snippet>
View script.sh
# Bash domain checker
# Usage: sh script.sh [domain name]
# If it says "No match for [domain]", it is available.
tlds=("com" "net" "co" "io" "co.uk")
for tld in "${tlds[@]}"
do
whois "$1.$tld" | grep "No match for";
done
View pubsub.js
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
View console-log.sublime-snippet
<snippet>
<content><![CDATA[console.log('$1', $1);]]></content>
<tabTrigger>log</tabTrigger>
<scope>text.html,source.js,source.jsx</scope>
<description>console.log()</description>
</snippet>