Skip to content

Instantly share code, notes, and snippets.

View harsh183's full-sized avatar
😺
People pleasing users

Harsh Deep harsh183

😺
People pleasing users
View GitHub Profile
@harsh183
harsh183 / download_all_rhtml_links.user.js
Created August 18, 2019 20:16
Userscript to downlaod all links from a given site - use Tampermonkey for Chrome or GreaseMonkey for firefox to run it (just copy paste this code and it should work)
require 'colorize'
require 'date'
def dash_seperator
'-' * 50
end
def get_date
Date.today.to_s
end
require 'sinatra'
# Ex. http://localhost:4567/calc/add?x=1&y=2
get '/calc/:operation' do
operations = { 'add' => ->(x, y) {x + y},
'sub' => ->(x, y) {x - y},
'mul' => ->(x, y) {x * y},
'div' => ->(x, y) {x / y},
'mod' => ->(x, y) {x % y} }
# Yes I could DRY that further but I don't trust user input
@harsh183
harsh183 / fibArray.rb
Last active April 16, 2021 15:33
A array except the indexes are fibonacci numbers!
class FibArray
attr_accessor :array, :cache
def initialize(array = [])
@array = array
@cache = [1, 2] # put precomputed results as needed
generate_next_fib(array.size - cache.size)
end
def get(i)
title
Testing 101

So far you've been writing your programs amd running them time and time again doing that. A constant cycle of change-run-repeat until it works.

Which works fine until

  • you have hundreds of scenarios and inputs
  • the program takes quite long to run and it starts eating up too much time
  • you accidently break your program and don't even realize (billions lost, rockets dailing, people dying)
@harsh183
harsh183 / upload_last_picture.sh
Last active April 23, 2021 13:20
Uploads the latest picture in my /Pictures directory to IMGBB and uses jq to parse out the image url
# This script goes into my Pictures/ folder and uploads it to ffsend.
# Requires: jq
set -e
cd ~/Pictures # configure to other source of pictures if you want
API_KEY="[YOUR KEY IT'S FREE TO GET]"
FILE_NAME=$(ls -rt | tail -n 1)
IMAGE=$( base64 "$FILE_NAME" )
@harsh183
harsh183 / index.md
Last active June 16, 2019 10:10
Find the only x, y, z positive integers such that x^3 = (z-y)^3 + 3yz(z-y) Presentation at: https://sleepy-noyce-8b3d2a.netlify.com/#1
theme marp
uncover
true

Find the only $x$, $y$, and $z$ positive integers

$$ x^3 = (z - y)^3 + 3yz(z - y)

#!/bin/bash
# This script is my standard create a new experiment for my new idea/side project/whatever that I normally seem to do. I can change this if I like as I move along.
set -ex
mkdir ~/Experiments/$1
cd ~/Experiments/$1
echo "# README" > README.md
#!/bin/bash
# This script is my standard create a new experiment for my new idea/side project/whatever that I normally seem to do. I can change this if I like as I move along.
set -e # Fail if one step fails
set -x # Print before execute
cd ~/Experiments/
mkdir $1
cd $1
<!DOCTYPE html><html lang="C"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0"><meta name="apple-mobile-web-app-capable" content="yes"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta property="og:type" content="website"><meta name="twitter:card" content="summary"><style>@media screen{body,html{background:#000;height:100%;margin:0;overflow:hidden}[data-bespoke-marp-fragment=inactive]{visibility:hidden}.bespoke-marp-osc{display:none;opacity:0}.bespoke-marp-parent{bottom:0;left:0;position:absolute;right:0;top:0}.bespoke-marp-parent>.bespoke-marp-osc{background:rgba(0,0,0,.65);border-radius:7px;bottom:50px;color:#fff;display:block;font-family:Helvetica,Arial,sans-serif;font-size:16px;left:50%;line-height:0;opacity:1;padding:12px;position:absolute;touch-action:manipulation;-webkit-transform:translateX(-50%);transform:translateX(-50%);transition:opacity .2s linear;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-