Skip to content

Instantly share code, notes, and snippets.

View msafadieh's full-sized avatar

Mohamad Safadieh msafadieh

View GitHub Profile
@msafadieh
msafadieh / merge_sheets.py
Last active January 9, 2019 11:19
a small google sheets script written out of necessity
'''
A small script I wrote to manipulate Google Sheets.
What this script does:
1. Opens a spreadsheet with two worksheets
2. Lays out the data of the second worksheet in a dict (the keys are street addresses
and the items are arrays)
3. Fetches cell range to manipulate
4. Iterates through the rows in the first sheet and looks in the generated dict for a
match (same street address)
5. If found, inserts the array content into the row.
@msafadieh
msafadieh / find_query.py
Created December 18, 2018 08:24
python recursive directory search
#! /bin/python3
'''
A little script that searches through folders for me and prints any files/dirs
that contain the query in the filename.
This is what happens when you don't really feel like going through the man of
the find command.
usage:
python3 find_query.py [query] [path]
@msafadieh
msafadieh / stars.rkt
Last active March 14, 2019 22:53
cool racket graphics
#lang racket
(require 2htdp/image)
(require 2htdp/universe)
(define (polygons n)
(let* ([random-color (lambda () (color (random 255) (random 255) (random 255)))]
[random-polygon (lambda (x) (star-polygon (* (add1 x) 30) (random 12 16) 11 'solid (random-color)))]
[polygons-list (build-list n random-polygon)]
[background (square (* 150 n) 'solid (random-color))])
@msafadieh
msafadieh / circles.rkt
Last active August 23, 2019 15:57
more cool racket graphics
#lang racket
(require 2htdp/image)
(require 2htdp/universe)
;; structure used
(struct crcl (radius color))
;; constants
(define SIZE 500)
@msafadieh
msafadieh / monty_hall_problem.py
Created March 27, 2019 05:16
simulation of the Monty hall problem
'''
a simulation of the Monty hall problem
'''
from random import choice, sample
TRIALS = 10000
def monty():
'''
runs a simulation of the monty problem. this program will switch
@msafadieh
msafadieh / resume.tex
Last active August 20, 2019 12:47
Latex Resume
\documentclass[fontsize=11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage[svgnames]{xcolor} % Colours by their 'svgnames'
\usepackage[margin=0.75in]{geometry}
\textheight=700px
\usepackage{url}
@msafadieh
msafadieh / sheets2docs.gs
Last active August 21, 2019 19:20
Builds a barebone Google Doc from Google Sheet entries
var folderName = "New Copy Center Jobs";
var columnsToSkip = 2;
function createDocument(lastRow) {
const doc = createDoc();
const sheet = SpreadsheetApp.getActiveSheet();
const fullRangeValues = sheet.getDataRange().getValues();
const titles = fullRangeValues[0];
@msafadieh
msafadieh / fetch_printer.py
Created September 19, 2019 17:46
Checks the paper status of campus printers by IP
import json
import requests
import re
from sys import argv
status = {"0": "Empty", "1": "Low", "2": "Normal", "3": "Full"}
data = {
"uri":"/rps/",
"userID":"",
"password":""
@msafadieh
msafadieh / namecheap.py
Created September 19, 2019 17:50
a very small client for Namecheap API that I needed for automation
from xml.etree import ElementTree as ET
import requests
NAMECHEAP_URL = "https://api.namecheap.com/xml.response"
class NamecheapClient:
def __init__(self, api_key, api_user, user_name, client_ip):
self.api_key = api_key
self.api_user = api_user
@msafadieh
msafadieh / wikisearch.js
Last active September 23, 2019 00:55
find shortest path from one wiki page to the other
import axios from 'axios'
export async function findShortestPath(firstPage, secondPage, callback, parent) {
if (state === undefined) {
state = {}
state.done = false;
state.visited = {}
state.visited[firstPage] = true;
}