Skip to content

Instantly share code, notes, and snippets.

@aswinsekar
aswinsekar / 1dpeak.cpp
Created October 7, 2018 07:35
Some interesting modules in cpp
// 1d peak finding problem in lecture 1
// peak referred to local maximum
// there will be multiple local maximum, we need to find atleast one
#include<bits/stdc++.h>
using namespace std;
int peak(int arr[],int start,int end,int n){
int mid = start + (end-start)/2;
//checking mid index elemenet as peak by comparing with neighbours if the neighbours exist
//2d peak
// algo 1, a combination of binary search along columns with brute force to find global maximum
#include<bits/stdc++.h>
using namespace std;
int m,n;
// to find global maximum in a given column
// helper function
int peakone(int **arr,int j,int n){
int max = 0;
for(int i=1;i<n;i++){
// IIFE - to print the trace where alert raised from
// Doesn't impact the alert behavior or any other behavior of your front end
// Add this code in your javascript or run it in console of your browser
// After adding, console will have stack trace of the alert printed
(function(proxied) {
window.alert = function() {
console.trace();
return proxied.apply(this, arguments);
};
@aswinsekar
aswinsekar / git.sh
Last active December 22, 2022 13:45
Git script Files
# delete local branches that no longer have remote reference
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
# delete files that are being ignored by git(.gitignore) under a directory
git clean -xdn # dry run all the files that will list all the gitignore files under the directory
git clean -xdf # to clean the files that are ignored
# to delete all the files in the git repo, execute the command in the root directory
# clone all repos of an org (requires ruby1.9+)
curl -s https://api.github.com/orgs/[ORGANIZATION]/repos | ruby -rjson -e 'JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'
@aswinsekar
aswinsekar / terminal.sh
Last active September 12, 2023 14:49
Bash Terminal command reference
#will list the calendar in the linux
cal
#Generate a sha256 sum of text
# for mac
echo -n <text> | shasum -a 256
# for linux
echo -n <text> | sha256sum
# sort and list the directories by size
@aswinsekar
aswinsekar / mac.sh
Last active March 5, 2023 17:32
mac specific commands
# to restart touchbar, when it is not responding or not working as expected
sudo pkill TouchBarServer
sudo killall “ControlStrip”
# 7zip handling in mac
brew install p7zip
p7zip x a.7z #extract module
@aswinsekar
aswinsekar / useTrailProp.js
Created August 16, 2020 13:08
This hook will not return anything. It will log into console, the changed props, from the previous render.
/**
* usage
*
* const MyComp = (props) => {
useTraceUpdate(props)
return <span />;
};
*/
import { useRef, useEffect } from "react";
@aswinsekar
aswinsekar / IANA timezone database.txt
Created September 16, 2020 11:11
IANA maintained timezone database for latest application development
codes coordinates TZ comments
AD +4230+00131 Europe/Andorra
AE,OM +2518+05518 Asia/Dubai
AF +3431+06912 Asia/Kabul
AL +4120+01950 Europe/Tirane
AM +4011+04430 Asia/Yerevan
AQ -6617+11031 Antarctica/Casey Casey
AQ -6835+07758 Antarctica/Davis Davis
AQ -6640+14001 Antarctica/DumontDUrville Dumont-d'Urville
AQ -6736+06253 Antarctica/Mawson Mawson
/*!
Math.uuid.js (v1.4)
http://www.broofa.com
mailto:robert@broofa.com
Copyright (c) 2010 Robert Kieffer
Dual licensed under the MIT and GPL licenses.
*/
/*
@aswinsekar
aswinsekar / flourish_credit_routing.js
Last active May 3, 2021 06:19
Routing code for Flourish book - https://flourishbooks.app/credits/ credits page
(function () {
if (location.href.indexOf("credits") !== -1) {
if (location.hash.length) {
var hash = location.hash;
var book = hash.split("-");
var hashFinalDone = false;
if (book[0]) {
book = book[0].split("#book")[1];
book = parseInt(book[0]);
if (isNaN(book)) {