Skip to content

Instantly share code, notes, and snippets.

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

shivshankar3578

🏠
Working from home
View GitHub Profile
@shivshankar3578
shivshankar3578 / index.ts
Created May 4, 2022 09:16
Add & Remove prefix from a key or all keys of a object using key remapping
type AddPrefix<TKey, TPrefix extends string> = TKey extends string ? `${TPrefix}${TKey}` : never
type RemovePrefix<TPrefixedKey, TPrefix extends string> = TPrefixedKey extends AddPrefix<infer TKey, TPrefix>
? TKey
: ""
type PrefixedValue<TObject extends object, TPrefixedKey extends string, TPrefix extends string> = TObject extends {
[K in RemovePrefix<TPrefixedKey, TPrefix>]: infer TValue
}
? TValue
@shivshankar3578
shivshankar3578 / no_two_adjacent.js
Created May 13, 2021 07:33
rearrange characters in a string such that no two adjacent are same
Array.prototype.swap = function (idx1, idx2) {
const temp = this[idx1];
this[idx1] = this[idx2];
this[idx2] = temp;
}
function rearrange(str) {
const weightMap = str.split("").reduce((acc, curr) => {
acc[curr] ? acc[curr] += 1 : acc[curr] = 1
@shivshankar3578
shivshankar3578 / foo.js
Created July 2, 2018 10:23 — forked from OliverJAsh/foo.js
Async iterators with map, skipWhile, and takeUntil
class FunctifiedAsync {
constructor(iterable) {
this.iterable = iterable;
}
async *[Symbol.asyncIterator]() {
for await (const value of this.iterable) {
yield value;
}
}
#!/usr/bin/env bash
function check_status_code {
local name=$1
local status=$2
if [ $status -ne 0 ]; then
echo $name failed with status code $status
exit $status
fi
echo Success: $name with code $status
// use std::fmt;
fn main() {
let name = format!("shiv shankar");
let new_name :String ;
println!("actual name = {:?}",name );
// shadow of name with mut
let (mut name, title_name) = title_case(name);
{
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@shivshankar3578
shivshankar3578 / aws-sns-example.js
Created July 21, 2017 11:50 — forked from tmarshall/aws-sns-example.js
aws-sdk sns example, in Node.js
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();