Skip to content

Instantly share code, notes, and snippets.

View kernelshreyak's full-sized avatar
💭
building innovative software

Shreyak Chakraborty kernelshreyak

💭
building innovative software
View GitHub Profile
@kernelshreyak
kernelshreyak / dstest.php
Last active February 21, 2019 07:11
PHP SPL Stack and Queue
<?php
//testing PHP Data Structures (SPL)
function displist($s){
echo "<br>";
$s->rewind();
while($s->valid()){
echo $s->current()." ";
$s->next();
@kernelshreyak
kernelshreyak / cardloader.php
Last active March 9, 2019 09:32
Custom PHP function to build a balanced deck using power distribution
<?php
function deckbuilder($gametype){ //custom deck builder function of 20 cards
global $dbconnect;
$cards=array();
//Build a balanced deck using power distribution
if($gametype==3) $pdist=[20,0,0]; //for pokemon cards no distribution
else $pdist=[14,5,1];
@kernelshreyak
kernelshreyak / loadcardsremote.php
Last active March 9, 2019 09:31
Remotely get card images directly via webpages and load them into databases and filesystems
<?php
// This code uses a kind of web scraping to get card images and load it into your filesystem and database
//This requires card data to be present in XML format (Cockatrice format works)
function copyfile($file_source, $file_target) {
$rh = fopen($file_source, "rb");
$wh = fopen($file_target, "wb");
if ($rh===false || $wh===false) {
// error reading or opening file
@kernelshreyak
kernelshreyak / tree.py
Last active November 10, 2024 15:26
Implementation of a generic tree data structure in Python
#Implementation of generic tree in Python
import random
import string
import pptree
class TreeNode(object):
"Node of a Tree"
def __init__(self, name='root', children=None,parent=None):
self.name = name
@kernelshreyak
kernelshreyak / hanoi.php
Created June 4, 2019 08:22
Tower of Hanoi solution implementation in PHP. Contents are also displayed
<?php
//Tower of Hanoi (n-disk) algorithm in PHP with Display of Pole Contents
//the 3 poles representation
$poles=array(array(),array(),array());
function TOH($n,$A="S",$B="I",$C="D"){
if($n>0){
/**
Algorithm implementation to check whether a given location (specified by an address) is within boundaries of a geographical region
(region name is also provided as input).
This uses Point In Polygon (PIP) algorithm[https://www.npmjs.com/package/@turf/boolean-point-in-polygon]
to check coordinate is inside our outside the polygon represented by the GeoJSON data.
Author: Shreyak Chakraborty
*/
@kernelshreyak
kernelshreyak / get_monitor_serial.sh
Last active February 21, 2025 15:39
Get Monitor Serial Number in Linux using EDID
for file in `ls -1 /sys/class/drm/*/edid`; do text=$(tr -d '\0' <"$file"); if [ -n "$text" ]; then edid-decode "$file" | grep -e Manufacturer: -e Product; sleep 0.0001; fi done
@kernelshreyak
kernelshreyak / array_diff.go
Created June 6, 2021 08:51
Array Diff in Golang
package main
import(
"fmt"
)
func main(){
arr1 := []int{1,2,3,5}
arr2 := []int{1,3,2,5,6,7}
found := make(map[int]bool)
@kernelshreyak
kernelshreyak / one_time_pad.py
Created July 28, 2022 15:48
Implementation of One Time Pad Cipher in Python
import os
import base64
class OneTimePad:
def encode_cipher(self,_string, key):
key = base64.b64decode(key)
retval = []
for k, v in zip(_string, key):
retval.append(int(ord(k) ^ v))
return base64.b64encode(bytes(retval))