Skip to content

Instantly share code, notes, and snippets.

View aryamansharda's full-sized avatar

Aryaman Sharda aryamansharda

View GitHub Profile
@aryamansharda
aryamansharda / SmartStudio.ino
Last active August 30, 2020 18:48
Code involved in automating my studio apartment's appliances.
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRutils.h>
#define WIFI_SSID "YOUR_NETWORK_NAME"
#define WIFI_PASS "YOUR_NETWORK_PASSWORD"
@aryamansharda
aryamansharda / DaemonBasics.c
Last active September 2, 2020 05:21
Basic implementation of a daemon in C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
static void create_daemon()
{
@aryamansharda
aryamansharda / LinearCongruentialGenerator.swift
Last active September 8, 2020 04:10
Linear Congruential Generator
import Foundation
final class LCG {
static func generate(modulus: Int, multiplier: Int, increment: Int, seed: Int) -> Int {
return (multiplier * seed + increment) % modulus
}
}
// Generating 100 random numbers using LCG
var seed = 0
@aryamansharda
aryamansharda / LinearCongruentialGenerator+Dice.swift
Created September 8, 2020 00:38
LinearCongruentialGenerator+Dice.swift
// Simulating Dice Roll
var seed = 0
for _ in 1...40000 {
let randomNumber = LCG.generate(modulus: 2147483648, multiplier: 1103515245, increment: 12345, seed: seed)
seed = randomNumber
let diceRoll = 1 + (randomNumber % 6)
print(diceRoll)
}
@aryamansharda
aryamansharda / LinearCongruentialGenerator+Range.swift
Created September 8, 2020 00:39
LinearCongruentialGenerator+Range.swift
// Simulating 1,000,000 random values in a given range
let upperBound: Double = 80
let lowerBound: Double = 30
let modulus = 2147483648
var seed = 0
for _ in 1...1000000 {
let randomNumber = LCG.generate(modulus: modulus, multiplier: 1103515245, increment: 12345, seed: seed)
seed = randomNumber
@aryamansharda
aryamansharda / GaussianBlur.swift
Created September 13, 2020 06:26
GaussianBlur
//
// GaussianBlur.swift
//
// Created by Aryaman Sharda on 9/12/20.
// Copyright © 2020 com.DigitalBunker. All rights reserved.
//
import Foundation
import UIKit
@aryamansharda
aryamansharda / HistogramBrightness.py
Last active January 9, 2021 05:28
HistogramBrightness
from PIL import Image
def boundedPixelValue(color, brightnessFactor):
scaledValue = float(color * (1 + brightnessFactor))
if scaledValue < 0:
return 0
elif scaledValue > 255:
return 255
return int(scaledValue)
@aryamansharda
aryamansharda / ContrastStretching.py
Created January 9, 2021 23:11
Contrast Stretching
from PIL import Image
# Converts image to grayscale
inputImage = Image.open("source.jpg").convert('L')
outputImage = Image.new('L', inputImage.size)
width, height = inputImage.size
# We first need to find the minimum and maximum pixel intensities
minIntensity = 255
@aryamansharda
aryamansharda / HistogramEqualization.py
Created January 9, 2021 23:13
Histogram Equalization
from PIL import Image
# Converts image to grayscale
inputImage = Image.open("source.png").convert('L')
outputImage = Image.new('L', inputImage.size)
width, height = inputImage.size
frequency = {}
@aryamansharda
aryamansharda / LZWEncoder.py
Created January 22, 2021 03:35
LZW Encoder
import sys
from sys import argv
from struct import *
def compress():
# Building and initializing the dictionary.
dictionary_size = 256
dictionary = {chr(i): i for i in range(dictionary_size)}
# We'll start off our phrase as empty and add characters to it as we encounter them