Skip to content

Instantly share code, notes, and snippets.

Avatar

Anjanesh Lekshminarayanan anjanesh

View GitHub Profile
@anjanesh
anjanesh / rallycoding.201.js
Last active Jan 28, 2021
Longest Increasing Sequence
View rallycoding.201.js
// https://www.rallycoding.com/problems/201
const solve = (intArray) =>
{
let a = [], l;
let b = [], m = 0;
let i, j;
for (i = 0; i < intArray.length - 1; i++)
{
@anjanesh
anjanesh / mega-menu.html
Created Jan 9, 2021
Mega Menu using CSS only
View mega-menu.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap" rel="stylesheet">
<title>Mega Menu using CSS only</title>
<style type="text/css">
body { font-family: Roboto; font-weight: normal; }
@anjanesh
anjanesh / number2words.js
Created Oct 20, 2020
Number to words (crore and lakh)
View number2words.js
const HUNDRED = 100;
const THOUSAND = HUNDRED * 10;
const LAKH = THOUSAND * 100;
const CRORE = LAKH * 100;
const TN = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
const TY = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'sixteen', 'eighty', 'ninety'];
const O = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
function number2words(num)
View contiguous-subarray.php
<?php
#$nums = [-2,1,-3,4,-1,2,1,-5,4];
$nums = [84,38,65,52,-9,70,81,58,-33,87,-47,48,23,-53,86,-2,45,56,35,5,90,47,-84,-21,55,-8,37,0,-3,-60,-11,-42,54,-68,-89,-54,-98,68,80,-31,55,-67,93,-45,-21,79,52,-75,12,-12,29,-21,-88,21,57,67,-87,-6,-33,-14,10,32,44,-35,63,54,-13,65,22,-33,-66,-46,0,-73,8,78,82,-62,79,-6,2,-15,72,13,83,30,-20,72,-99,46,-41,11,-21,-97,52,-81,33,-61,83,-45,-18,-83,-15,81,-80,69,37,-98,-93,-7,-28,8,55,-55,-78,38,51,-22,-13,51,-75,45,-61,-20,24,90,-2,-43,-94,-41,-12,-12,-25,72,-54,-28,42,59,-27,25,-70,22,-89,84,66,-91,-1,-6,-14,85,-78,-13,8,-39,66,-68,-72,-58,-11,-89,0,53,-25,51,26,20,-77,-55,-43,-27,46,-14,94,33,-53,37,41,45,-69,-72,7,-48,14,-85,-11,-42,-76,-6,-1,-11,4,98,-58,78,49,44,-25,49,65,31,-78,12,93,-84,-55,-83,52,86,61,59,90,-54,-89,-19,-63,-23,38,-40,47,-86,48,-49,-88,67,-94,38,11,-43,-36,-23,65,-15,65,58,-23,-90,75,-94,72,13,64,62,35,51,-79,72,-72,58,-91,74,72,34,-98,60,1,83,-25,-88,-59,38,-35,-94,99,-70,40,-47,-83,15,-42,88,-94,-78,28,40,73,48,-11,77,-17,-2,29,-68,-68,7,69,9
View brackets.js
/*
Usage :
node brackets.js
((a+b*d)*(x/2))*(1+(y+(x-2)/10))
[ '(a+b*d)',
'(x/2)',
'((a+b*d)*(x/2))',
'(x-2)',
'(y+(x-2)/10)',
View brackets.php
<?php
$s = "((a+b*d)*(x/2))*(1+(y+(x-2)/10))";
$b = [];
$j = 0;
$stack = [];
for ($i = 0; $i < strlen($s); $i++)
{
if ($s[$i] == '(')
{
@anjanesh
anjanesh / commas.html
Created Apr 28, 2019
Commas in INPUT textfields
View commas.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<div id="container">
<form id="frm" class="form" action="" method="post">
<div>
<div>
@anjanesh
anjanesh / getter-setter
Created Jan 5, 2013
StackOverflow closed my question http://anjane.sh/Z6G4YX while I got it answered at devnetwork http://anjane.sh/RxY6Vh
View getter-setter
<?php
class A
{
protected $_data;
public function __get($name)
{
if (in_array($name, ['Firstname', 'Lastname']))
return $this->_data[$name];
}
@anjanesh
anjanesh / csv-json.py
Last active Apr 28, 2019
Convert CSV to JSON
View csv-json.py
import sys, csv, json
if len(sys.argv) == 1:
print "1 argument for filename required"
sys.exit()
gdoc = csv.reader(open(sys.argv[1]))
# Get the 1st line, assuming it contains the column titles
fieldnames = gdoc.next()
@anjanesh
anjanesh / find-intersection-among-arrays.js
Created Oct 13, 2011
Find Intersection Among Arrays
View find-intersection-among-arrays.js
/*
ar : can be an array of arrays or an asssociative array
Examples:
================
intersect([[76,80,11,31,34,82,100], [13,31,66,43,73,100,73,10]])
will give [31,100]
intersect(