Skip to content

Instantly share code, notes, and snippets.

@codervinod
codervinod / retry_helper.sh
Created August 22, 2022 19:14
Bash backoff helper implementation
#!/bin/bash
set -x
set -e
# Retries a command a with backoff.
#
# The retry count is given by ATTEMPTS (default 10), the
# initial backoff timeout is given by TIMEOUT in seconds
# (default 5.)
@codervinod
codervinod / docker_copy.go
Last active July 21, 2016 15:37
Copies Docker repo from one to another
package main
import (
"bytes"
"fmt"
"io/ioutil"
"crypto/sha256"
"encoding/hex"
"github.com/heroku/docker-registry-client/registry"
"github.com/docker/distribution/digest"
@codervinod
codervinod / dupletSumTarget.cpp
Created January 25, 2015 04:33
Find a pair of elements from an array whose sum equals a given number
#include <unordered_map>
#include <iostream>
void printArray(int ar[], int high)
{
for (int i = 0; i < high; ++i)
{
std::cout << ar[i] << "\t";
}
std::cout << std::endl;
@codervinod
codervinod / tripletSumTarget.cpp
Created January 24, 2015 23:10
Given an array of numbers, find out if 3 of them add up to
#include <vector>
#include <iostream>
#include <algorithm>
void printArray(int ar[],int high)
{
for (int i = 0; i < high; ++i)
{
std::cout << ar[i] << "\t";
}
@codervinod
codervinod / binarySearch.cpp
Created January 24, 2015 22:49
Binary Search
#include <iostream>
int binarySearch(int ar[], int low, int high, int search)
{
if (low > high)
return -1;
int mid = (low + high) / 2;
if (ar[mid] < search)
{
return binarySearch(ar, mid+1, high, search);
@codervinod
codervinod / quickSort.cpp
Created January 24, 2015 22:48
Quick sort algo
#include <iostream>
int partition(int ar[], int low, int high)
{
int pivot = ar[(low + high) / 2];
while (low <= high)
{
while (ar[low] < pivot) low++;
while (ar[high] > pivot) high--;
@codervinod
codervinod / anagrams.cpp
Created January 24, 2015 22:47
Finding anagrams for a given word
#include <vector>
#include <iostream>
#include <math.h>
#include <list>
#include <map>
#include <unordered_map>
std::vector<int> prime_vct;
@codervinod
codervinod / std_algo.cpp
Created January 24, 2015 22:45
Using STL to demonstrate STL find and sort
#include <vector>
#include <iostream>
#include <algorithm>
bool compare(int a, int b)
{
return (a > b);
}
void sort(std::vector<int> &ar)
@codervinod
codervinod / efficientPrime.cpp
Created January 21, 2015 12:47
Efficient Prime number generator
#include <vector>
#include <iostream>
#include <math.h>
void primeGenerator(std::vector<int> &prime_vct, unsigned int maxPrime)
{
prime_vct.push_back(1);
prime_vct.push_back(2);
for (unsigned int i = 3; i < maxPrime; i += 2)
@codervinod
codervinod / numParity.cpp
Created January 20, 2015 23:36
Calculate number of parity bits
#include <iostream>
#include <Windows.h>
long long milliseconds_now() {
static LARGE_INTEGER s_frequency;
static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency);
if (s_use_qpc) {
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
return (1000LL * now.QuadPart) / s_frequency.QuadPart;