Skip to content

Instantly share code, notes, and snippets.

View spunkypanda's full-sized avatar
🏠
Working from home

Chinmay Bag spunkypanda

🏠
Working from home
View GitHub Profile
@spunkypanda
spunkypanda / rules for good testing.md
Created February 6, 2018 19:14 — forked from Integralist/rules for good testing.md
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.

@spunkypanda
spunkypanda / latency.txt
Created January 19, 2019 19:41 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@spunkypanda
spunkypanda / deleteAllGitBranchesExceptOfDevStagingMaster
Last active June 12, 2019 04:44 — forked from anvk/deleteAllGitBranchesExceptOfDevelop
Delete all Git local branches except dev, staging, master
git branch | grep -v "dev\|staging\|master" | xargs git branch -D
@spunkypanda
spunkypanda / app.js
Created January 18, 2020 20:42 — forked from stongo/app.js
Joi validation in a Mongoose model
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', function() {
return console.error.bind(console, 'connection error: ');
});
@spunkypanda
spunkypanda / postgres-cheatsheet.md
Created February 9, 2020 08:40 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@spunkypanda
spunkypanda / error-handling-with-fetch.md
Created February 20, 2020 14:10 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@spunkypanda
spunkypanda / sendmail_setup.md
Created June 3, 2020 16:42 — forked from kany/sendmail_setup.md
Setup SENDMAIL on Mac OSX Yosemite
@spunkypanda
spunkypanda / removeKeys.js
Created January 18, 2021 10:25 — forked from aurbano/removeKeys.js
Remove a property from a nested object, recursively
/**
* Remove all specified keys from an object, no matter how deep they are.
* The removal is done in place, so run it on a copy if you don't want to modify the original object.
* This function has no limit so circular objects will probably crash the browser
*
* @param obj The object from where you want to remove the keys
* @param keys An array of property names (strings) to remove
*/
function removeKeys(obj, keys){
var index;