Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
@deepak
deepak / how-typescript-won.md
Created January 30, 2024 09:44
How/Why did TypeScript beat Flow
@deepak
deepak / standard-commit-message.txt
Created September 15, 2017 05:38
standard commit message with gitmoji
### standard commit message
Am using commitzen for the git commit message
It is a one liner eg: `<type>(<scope>): <subject> :gitemoji:`
`type` can be chore, feat or docs
`scope` can be `html`, `css`, `js` or `lint`
and `scope` is optional
`gitemoji` maybe
@deepak
deepak / flow-maybe.js
Last active August 9, 2017 12:06
flow has no Maybe type
// @flow
// https://flow.org/en/docs/types/unions/#toc-disjoint-unions
type Response = {
success: boolean,
value?: boolean,
error?: string
};
// works.
@deepak
deepak / flow-union-refinement.js
Last active August 9, 2017 09:47
flow-union-refinement
// @flow
// https://flow.org/en/docs/types/unions/#toc-unions-refinements
// flow can refine on the union.
// and knows when the code is operating on a number here for eg.
// works
function toStringPrimitivesGood(value: number | boolean | string): string { // Error!
if (typeof value === 'number') {
return value.toLocaleString([], { maximumSignificantDigits: 3 }); // Works!
// chaining then. chain is then -> catch -> then
// case 1: promise is resolved
new Promise((resolve, reject) => resolve("some data")).then(data => { alert(`data: ${data}`); return data; }).catch(err => { alert(`err: ${err}`); return Promise.reject(err); }).then(data => { alert(`data again: ${data}`); return data; })
// case 2: promise is rejected
new Promise((resolve, reject) => resolve("some data")).then(data => { alert(`data: ${data}`); return data; }).catch(err => { alert(`err: ${err}`); return Promise.reject(err); }).then(data => { alert(`data again: ${data}`); return data; })
@deepak
deepak / rust-slice-panics.rs
Last active August 7, 2017 04:27
rust-slices.txt
fn main() {
let mut s = String::from("hello world");
let len = first_word(&s);
{
let word = &s[0..len];
println!("word is {}", word); // word is hello
}
s.clear();
let word = &s[0..len]; // thread 'main' panicked at 'byte index 5 is out of bounds of ``', src/libcore/str/mod.rs:2144
println!("word is {}", word);
@deepak
deepak / node.eslint.json
Created July 11, 2017 06:49
EsLint rules
{
"env": {
"node": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
"array-bracket-spacing": [
@deepak
deepak / use-currying.js
Created February 14, 2017 12:57
use currying
let MODIFY = "MODIFY";
let ADD = "ADD";
let DELETE = "DELETE";
function checkAction(actions, recon, action, cb) {
if (actions.indexOf(action) > -1) {
cb(recon);
}
}
@deepak
deepak / deep-es6-destructuring.js
Created February 14, 2017 08:12
deep destructuring in ES6
const params = {
pagination: {
prevId:1,
nextId: 3
},
location: {
query: {
step: 10
}
}
@deepak
deepak / better react devtools.md
Created February 3, 2017 06:42
better react devtools

better react devtools

  • which React component is rendered at the top-level
  • performance information
  • error page