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
require 'pry'
require 'rqrcode'
qrcode = RQRCode::QRCode.new('https://cs125.cs.illinois.edu')
png = qrcode.as_png(
bit_depth: 1,
border_modules: 4,
color_mode: ChunkyPNG::COLOR_GRAYSCALE,
color: 'black',
@harsh183
harsh183 / mypy-example.py
Last active July 1, 2021 17:26
A small exploration with mypy and python type annotations.
# Simple script I put together showing mypy in action
# standard type annotations - we can give arguments a type and expect a return type
def add(x: int, y: int) -> int:
return x + y
print(add(1, 2))
# we can let it pick within a list of types
from typing import Union
#!bin/bash
# This script is for me creating my brain dumps that I usually do jumping right into it in vim.
# I have a template file also defined that I can setup if I want.
# This script also brings me back to the same context that I was in earlier
set -ex
cd ~/brain-dumps/
@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)