Skip to content

Instantly share code, notes, and snippets.

View AmosAidoo's full-sized avatar
🎯
Focusing

Amos Aidoo AmosAidoo

🎯
Focusing
View GitHub Profile
class Solution {
public:
int solve(vector<vector<char>>& grid, int r, int c) {
if (!(r >= 0 && r < grid.size())) return 0;
if (!(c >= 0 && c < grid[r].size())) return 0;
if (grid[r][c] == '0') return 0;
grid[r][c] = '0';
solve(grid, r, c-1);
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
@AmosAidoo
AmosAidoo / md5.py
Created July 15, 2021 11:39
Implementation of MD5 from RFC 1321 in python
"""
The MD5 is an algorithm that takes as input a message
of arbitrary length and produces as output a 128-bit "fingerprint"
or "message digest" of the input. Source: RFC 1321
"""
# Constants
T = [0] * 64
T[ 0: 3+1] = [ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee ]
T[ 4: 7+1] = [ 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501 ]
import numpy as np
import sys
from numpy import linalg as LA
"""
This function takes square matrix and returns
the dominant eigin value and the smallest eigen value
and the value closest to a scalar k
"""
def solve(sq_matrix, k):
@AmosAidoo
AmosAidoo / scale_and_pan.js
Created March 24, 2021 09:40
Simple snippet to scale and pan the canvas of a p5.js sketch
let x,y,scl,delta,panSpeed
let translateX, translateY, prevX, prevY
function setup() {
createCanvas(400, 400)
delta = 1 // Will be -1 or 1 depending on the direction of the pan
panSpeed = 6 // How fast does the pan move
translateX = width/2
translateY = height/2
@AmosAidoo
AmosAidoo / backend-stuff.md
Last active January 7, 2021 10:17
Just noting down stuff I find about backend development

Languages

Java, Scala, Nodejs, Go, Ruby, .NET, Python

Technologies

  • Hadoop
  • Spark
  • Kafka
  • Flink
  • Docker
  • Kubernetes
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
package main
import (
"fmt"
)
// Sample test data for the algorithm
var (
PLAIN_TEXT = []byte("Text")
KEY = []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
self._id = 0
def area(self):
return self.width * self.height
def perimeter(self):
@AmosAidoo
AmosAidoo / solution.py
Created October 5, 2020 13:03
Solution
def solution(h, q):
root = (1 << h) - 1
l = h-1
queue = [root-(1<<l), root-1]
parent = [0 for _ in range(root+1)]
parent[root] = -1
parent[queue[0]] = root
parent[queue[1]] = root
pows = 2