Skip to content

Instantly share code, notes, and snippets.

View kumarldh's full-sized avatar
🏠
Working from home like everyone else...

Kumar Chetan Sharma kumarldh

🏠
Working from home like everyone else...
View GitHub Profile
@kumarldh
kumarldh / logger.js
Created April 17, 2024 04:48
My Winstorn logging set up
const winston = require('winston');
require('winston-daily-rotate-file');
const { format } = winston;
const { combine, json, timestamp } = format;
const logDir = process.env.LOGDIR || './logs';
const transports = [];
if (process.env.ENVIRONMENT === 'dev') {
transports.push(
new winston.transports.Console({
@kumarldh
kumarldh / pm2run
Created June 6, 2018 12:26
run pm2 with watch and inspect
./node_modules/pm2/bin/pm2 delete all; ./node_modules/pm2/bin/pm2 start ./{path to server js} --watch --node-args='--inspect' --no-daemon
@kumarldh
kumarldh / dr-strange.html
Created May 28, 2018 04:16
Was watching Dr. Strange, thought that those "strange" green animations can be done using CSS...? I think yes
<!DOCTYPE html>
<html>
<head>
<title>JLT - Animated squares on top of a circle</title>
<style>
body{
padding: 300px;
}
div{
position: absolute;
@kumarldh
kumarldh / n-ary-number-system.php
Created March 18, 2018 08:56
Given a decimal number and a base, convert the number to n-ary base number.
<?php
/**
* Given a decimal number and a base, convert the number to n-ary base number. Also find a way to perform arithmetic
* operations. The n is actually 36, however the principal is same.
*
* To perform arithmetic operations, we convert the number back to decimal, do the math, then convert back to the
* original base.
*/
/**
@kumarldh
kumarldh / handyregexes
Created October 7, 2017 05:11
some handy regexes, cuz regexes are hard for regular humans
find all console.log()
console\.log\((.*)\);
@kumarldh
kumarldh / precommithookforphpandjson
Created September 6, 2017 06:38
a pre commit hook for PHP and JSON file
#!/bin/bash
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_PHP_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
STAGED_JSON_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.json$`
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
@kumarldh
kumarldh / server.js
Created April 13, 2017 09:14
a small example on how to handle routing, not meant for production use
var http = require('http'), //http server
urlparser = require('url'), //url parser & builder
host = 'sandbox',
port = 1337;
http.createServer(function (req, res) {
var response = 'Hello, World!\n',
url = urlparser.parse(req.url, true).pathname;
switch (url) {
case('/hello'): //check for path, alternatively strip the front slash
response = 'World!\n';
@kumarldh
kumarldh / server.js
Created April 13, 2017 09:14
a small example on how to handle routing, not meant for production use
var http = require('http'), //http server
urlparser = require('url'), //url parser & builder
host = 'sandbox',
port = 1337;
http.createServer(function (req, res) {
var response = 'Hello, World!\n',
url = urlparser.parse(req.url, true).pathname;
switch (url) {
case('/hello'): //check for path, alternatively strip the front slash
response = 'World!\n';
@kumarldh
kumarldh / bashrc
Last active March 1, 2017 11:00
Some shortcuts I need in basrc
command_exists () {
type "$1" &> /dev/null ;
}
# grep always with color and line number
alias grep='grep -n --color=always'
# git
if command_exists git ; then
alias gitco='git checkout'
@kumarldh
kumarldh / niginx.conf
Created February 27, 2017 06:05
example nginx conf for reverse proxy on Apache
server {
listen 80;
server_name helloworld;
location / {
rewrite ^/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;