Skip to content

Instantly share code, notes, and snippets.

View svdamani's full-sized avatar
🎯
Focusing

Shreevardhan svdamani

🎯
Focusing
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.CompilerServices;
public static class ObjectExtensions {
public static void Dump(this Object o) {
Console.WriteLine("{0,-30} {1}", "Name", "Value");
Console.WriteLine("-----------------------------------------------------------------");
foreach (var prop in o.GetType().GetProperties())
(function(w) {
"use strict";
function ajax(method, url, callback, data) {
return (function(x) {
x.onreadystatechange = function() {
x.readyState ^ 4 || callback(this);
};
x.open(method, url, callback);
x.send(data);
@svdamani
svdamani / FileSize.java
Last active August 29, 2015 14:23
Calculate size of file system sub tree in Java (java.nio.files.*)
/**
* File : FileSize.java
* Purpose : Concurrently process a filesystem sub-tree and calculate it's size
* Author : Shreevardhan
* Compilation : `javac FileSize.java`
* Execution : `java FileSize <path> <threads>`
*/
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
@svdamani
svdamani / crc32.js
Created June 13, 2015 10:23
CRC Implementation in JavaScript
function CRC() {
var table = new Array(256), /// LookUp Table for CRC
initial = 0xFFFFFFFF; /// Initial CRC
return {
/// Reverse a polynomial
reverse: function(poly) {
var rev = 0;
for(var i = 0; i < 32; i++) rev = rev << 1 | (poly >>> i) & 1;
return rev;
},
@svdamani
svdamani / spline.c
Last active January 20, 2024 02:50
Natural Cubic Spline Interpolation in C
/** Numerical Analysis 9th ed - Burden, Faires (Ch. 3 Natural Cubic Spline, Pg. 149) */
#include <stdio.h>
int main() {
/** Step 0 */
int n, i, j;
scanf("%d", &n);
n--;
float x[n + 1], a[n + 1], h[n], A[n], l[n + 1],
u[n + 1], z[n + 1], c[n + 1], b[n], d[n];
@svdamani
svdamani / Timer2.hpp
Last active August 29, 2015 14:21
C++ 11 Timer class
#include <chrono>
#include <thread>
template <typename T = std::chrono::milliseconds>
class Timer {
typedef std::chrono::high_resolution_clock clock;
public:
Timer() : start(clock::now()) {}
inline void reset() { start = clock::now(); }
@svdamani
svdamani / bing.ps1
Last active July 31, 2016 05:11
Powershell script to set Bing wallpaper as desktop background
[CmdletBinding()]
Param (
[ValidateRange(0, 18)] [int] $idx = 0,
[ValidateSet("en-US", "en-IN")] [string] $mkt = "en-IN"
)
$url = "http://www.bing.com/HPImageArchive.aspx?format=js&n=1&mkt=$mkt&idx=$idx"
$url = "http://www.bing.com" + (Invoke-RestMethod $url).images[0].url
$file = (Resolve-Path "~\Pictures\BingDesktop\").Path + $url.Split('/')[-1].Split('_')[0] + ".jpg"
if (-NOT (Test-Path $file)) { Invoke-WebRequest $url -OutFile $file }
Set-ItemProperty Wallpaper -Path "HKCU:\Control Panel\Desktop" -Value $file
@svdamani
svdamani / bing.sh
Created April 18, 2015 13:51
Bash script to set Bing wallpaper as desktop background
#!/bin/bash
# Get day from command line (default 0)
[ "$#" -ne 1 ] && set -- "0"
# Options
dir=~/Pictures/BingDesktop/ # Working directory
day="&idx=$1" # Set day. 0 is current day, 1 is previous day, ...
num="&n=1" # No. of images to get
mkt="&mkt=en-IN" # Set required market
@svdamani
svdamani / mylib.h
Created April 17, 2015 16:38
A C library of simple and useful functions
/*
* Compilation : Include this file in a C program
* Compile with an extra flag
* $compiler -std=c99 $executable $program
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
@svdamani
svdamani / pow.py
Last active April 17, 2020 10:44
Fast Power calculation in Python
def power(base, exp):
""" Fast power calculation using repeated squaring """
if exp < 0:
return 1 / power(base, -exp)
ans = 1
while exp:
if exp & 1:
ans *= base
exp >>= 1
base *= base