Skip to content

Instantly share code, notes, and snippets.

View SandeepTuniki's full-sized avatar

Sandeep Tuniki SandeepTuniki

View GitHub Profile
@SandeepTuniki
SandeepTuniki / quick_sort_spec.rb
Created June 4, 2021 10:44
Specs for quick sort
# spec/quick_sort_spec.rb
require 'quick_sort'
RSpec.describe QuickSort do
tests = [
{input: [2, 1, 1], want: [1, 1, 2]},
{input: [6, 2, 0, 1, -3], want: [-3, 0, 1, 2, 6]},
{input: [], want: []},
{input: [1], want: [1]},
@SandeepTuniki
SandeepTuniki / quick_sort.rb
Last active June 4, 2021 13:46
Table-driven tests in Ruby
# lib/quick_sort.rb
class QuickSort
def initialize(arr)
@arr = arr
end
def sort
sort_subarray(0, @arr.length - 1)
return @arr
@SandeepTuniki
SandeepTuniki / watch.sh
Created February 1, 2017 15:59 — forked from mikesmullin/watch.sh
watch is a linux bash script to monitor file modification recursively and execute bash commands as changes occur
#!/usr/bin/env bash
# script: watch
# author: Mike Smullin <[email protected]>
# license: GPLv3
# description:
# watches the given path for changes
# and executes a given command when changes occur
# usage:
# watch <path> <cmd...>
#
@SandeepTuniki
SandeepTuniki / complement.cpp
Last active January 25, 2017 04:01
This program complements the bits from first most significant '1' bit to the remaining least significant bits, leaving the remaining highest significant bits intact.
#include <bits/stdc++.h>
using namespace std;
int getComplem(int n) {
int b = 0;
for (int temp = n; temp != 0; temp >>= 1) {
b++;
}
return ~((~n)^((1 << b) - 1));
}
@SandeepTuniki
SandeepTuniki / index.html
Last active December 2, 2016 10:02
Moving circles
<html>
<head></head>
<body>
<svg width="960" height="500"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script src="index.js"></script>
</body>
</html>
@SandeepTuniki
SandeepTuniki / custom-priority-queue.cpp
Last active October 17, 2016 09:00
Priority Queue (Heap)
template<typename T>
class custom_priority_queue : public std::priority_queue<T, std::vector<T>>
{
public:
bool remove(const T& value) {
auto it = std::find(this->c.begin(), this->c.end(), value);
if (it != this->c.end()) {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
@SandeepTuniki
SandeepTuniki / graph-template.cpp
Last active October 16, 2016 04:06
Graph Template for c++
struct Node {
int id;
unordered_map<int, *Node> neighbours;
};
struct Edge {
Node *source;
Node *dest;
int weight;
@SandeepTuniki
SandeepTuniki / lcm-gcd.cpp
Last active June 7, 2023 19:48
c++ competitive programming template
int gcd(int a, int b)
{
while (true)
{
if (a == 0) return b;
b %= a;
if (b == 0) return a;
a %= b;
}
}
@SandeepTuniki
SandeepTuniki / countCSSRules.js
Created October 3, 2016 06:19 — forked from psebborn/countCSSRules.js
Count the number of rules and selectors for CSS files on the page. Flags up the >4096 threshold that confuses IE
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@SandeepTuniki
SandeepTuniki / gitkeep
Created August 24, 2016 08:55 — forked from simoncoulton/gitkeep
Create empty gitkeep files in directories that are empty
find . -type d -empty -exec touch {}/.gitkeep \;