Skip to content

Instantly share code, notes, and snippets.

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

SP Singh spcheema

🏠
Working from home
View GitHub Profile
@spcheema
spcheema / System Design.md
Created July 10, 2023 14:20 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@spcheema
spcheema / current-datetime-based-on-timezone.js
Last active February 28, 2019 23:01
Current date object conversion based on the given timezone string.
/**
* Return current date object according to given timezone. Date will be return based on system's timezone an error occured while parsing
*
* @param timezone Timezone string e.g. `America/Los_Angeles`
* @returns {Date}
*/
function currentDate(timezone) {
try {
return new Date(new Date().toLocaleString("en-US", {timeZone: timezone}));
} catch (error) {
@spcheema
spcheema / pdo-statment-to-query.php
Last active February 18, 2019 23:31
Get a raw query from prepared pdo statement help for debugging.
/**
* Replaces any parameter placeholders in a query with the value of that
* parameter. Useful for debugging. Assumes anonymous parameters from
* $params are are in the same order as specified in $query
*
* @param string $query The sql query with parameter placeholders
* @param array $params The array of substitution parameters
* @return string The interpolated query
*
* @link https://stackoverflow.com/questions/210564/getting-raw-sql-query-string-from-pdo-prepared-statements
@spcheema
spcheema / Get started with React & Babel.markdown
Created July 8, 2016 07:34
Get started with React & Babel
@spcheema
spcheema / lib-index.coffee
Created July 2, 2016 13:59
10 Word Count Puzzle Solution
through2 = require 'through2'
module.exports = ->
words = 0
lines = 1
transform = (chunk, encoding, cb) ->
# Count lines
if chunk.match(/\n/mg)
@spcheema
spcheema / index.coffee
Last active July 2, 2016 14:00
Memory Puzzle solution
fs = require 'fs'
exports.countryIpCounter = (countryCode, cb) ->
return cb() unless countryCode
fs.readFile "#{__dirname}/../data/geo.txt", 'utf8', (err, data) ->
if err then return cb err
counter = 0
data = data.toString()