Skip to content

Instantly share code, notes, and snippets.

View ahmedsakr's full-sized avatar
💻
Coding from home

Ahmed Sakr ahmedsakr

💻
Coding from home
  • Wealthsimple
  • Ottawa, ON, Canada
View GitHub Profile
import { Mutex, Semaphore } from 'async-mutex';
import material from 'materialize-css/dist/js/materialize';
let count = 0;
let clientLock = new Mutex();
let clientSempahore = new Semaphore(2);
// Server Simulation
function processCommand() {
count += 1;
@ahmedsakr
ahmedsakr / synchronized-count.js
Last active August 13, 2020 22:56
A synchronized solution to the Ordered Server Counter Example
import { Mutex } from 'async-mutex';
import material from 'materialize-css/dist/js/materialize';
let count = 0;
let clientLock = new Mutex();
// Server Simulation
function processCommand() {
count += 1;
return count;
@ahmedsakr
ahmedsakr / naive-approach.js
Created August 13, 2020 22:44
A naive approach to implementing the Ordered Server Counter
import material from 'materialize-css/dist/js/materialize';
let count = 0;
// Server simulation
async function processCommand() {
count += 1;
return count;
}
@ahmedsakr
ahmedsakr / hacked.html
Created August 11, 2020 02:24
A sample HTML page that can carry out CSRF attacks
<!DOCTYPE html>
<html>
<header>
<title>I'm a trusted page</title>
</header>
<!-- Immediately dispatch the forum when we load-->
<body onload="document.hackform.submit()">
<!-- Nothing suspicious... show the user a happy cat! -->
@ahmedsakr
ahmedsakr / aws.yml
Created August 9, 2020 01:44
YAML file for uploading lambda to AWS
service: FortuneCookie
provider:
name: aws
runtime: nodejs12.x
profile: myaws
region: ca-central-1
stackName: fortune-backend
package:
@ahmedsakr
ahmedsakr / fortune.js
Last active August 9, 2020 01:34
Handler for requesting a fortune
export function requestFortune() {
fetch('https://a9vymko126.execute-api.ca-central-1.amazonaws.com/test', { method: "GET" })
.then(response => response.json())
.then(data => document.getElementById('fortune-text').innerHTML = data)
}
@ahmedsakr
ahmedsakr / requestFortune.js
Last active August 9, 2020 01:05
requestFortune lambda for the Fortune Cookie Serverless application
const fortunes = [
"A beautiful, smart, and loving person will be coming into your life.",
"A dubious friend may be an enemy in camouflage.",
"A faithful friend is a strong defense.",
"A feather in the hand is better than a bird in the air.",
"A fresh start will put you on your way.",
"A friend asks only for your time not your money."
];
/**
@ahmedsakr
ahmedsakr / style.scss
Created August 6, 2020 04:30
Stylesheet for rfs demo
@import "./node_modules/rfs/scss.scss";
body {
margin: 0;
}
#content-container {
display: flex;
height: 100vh;
flex-direction: column;
@ahmedsakr
ahmedsakr / DPVector.py
Created August 3, 2020 05:06
Overriding default __mul__ class implementation
class DPVector(tuple):
'''
Dot Product (DP) Vector class that overrides the __mul__
implementation to perform dot product operation!
'''
def __init__(self, tup):
self.tup = tup
def __mul__(self, other):
'''
@ahmedsakr
ahmedsakr / Medium.py
Created August 3, 2020 04:53
An example showcasing the need for developer friendly messages
class Medium(object):
def __init__(self, username, age, interests):
self.username = username
self.age = age
self.interal_id=2939
self.interests = interests
def __str__(self):
'''