Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Nidhal Selmi Nydhal

🎯
Focusing
View GitHub Profile
@Nydhal
Nydhal / hn_upvoted_scraper.js
Created Jul 25, 2020
Scrape all your HN upvoted links and Export to CSV or HTML (from your browser).
View hn_upvoted_scraper.js
/*
Search HN upvoted from your browser and Export to CSV or HTML.
1. Navigate your browser to https://news.ycombinator.com/user?id=YOUR_USER_ID
2. Copy code to the browser console and run.
4. Look for the popup window in the upper-left corner of your browser.
*/
(function () {
const popup = createPopup('HN upvoted');
const base = 'news.ycombinator.com';
@Nydhal
Nydhal / coupon_cover.py
Created Dec 4, 2019
Python Simulation of the Coupon Collector Problem Expectation a.k.a Mean Cover Time of a Random Walk on a Complete Graph K_n (n=52, 10000 trials).
View coupon_cover.py
import random as rd
for _ in range(10000): seen, n_draws = set(), 0
while len(seen)<52:
seen.add(rd.randint(1,52))
n_draws +=1
result.append(n_draws)
print (sum(result) / len(result))
View sleepfizzbuzz
import asyncio
async def FizzBuzz(i: int):
await asyncio.sleep(i)
print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or i)
async def SleepFizzBuzz(l,loop):
tasks = [loop.create_task(FizzBuzz(i)) for i in range(1,l+1)]
for t in tasks:
await t
View Corr_Matrix_Generation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View digikey_parser.py
# coding=utf-8
import urllib3 as u
from bs4 import BeautifulSoup
from tabulate import tabulate
import pandas as pd
digikey_id_list = ['product-details', 'prod-att-table'] # Digi-Key tables
def get_soup(url):
@Nydhal
Nydhal / audio.html
Last active Jul 6, 2018
Stylized HTML5 audio player
View audio.html
<!DOCTYPE html><html><body>
<style> audio { filter:
sepia(100%)
saturate(220%)
grayscale(0)
contrast(60%)
hue-rotate(50deg)
invert(100%)
drop-shadow(0px 0px 0px #ff0000);
</style>
View getA2B_solution.py
from sympy import binomial as b
def getA2B(X,Y,x,y):
U,D,s = X==x,Y==y,x+y
u = sum([b(s,i) for i in range(0,y)])
d = sum([b(s,i) for i in range(y+1,s+1)])
r = u*U+b(s,y)+D*d
return r/2**s
print('B(3,4) C(3,3) => ',getA2B(3,4,3,3))
# Problem represnetation :
# Enter destination coordinates B(X,Y) and intercept point C(x,y)
@Nydhal
Nydhal / run_calc.py
Last active Apr 26, 2018
#Python code to sample n trials given N and M (short but not best way) https://twitter.com/CutTheKnotMath/status/989147356129058816
View run_calc.py
import random as r,itertools as t
def s(M,N,L=[0]):
while len(L)<M+1:
x=r.randint(1,N)
if x!=L[-1]:L.append(x)
return len([x[0] for x in t.groupby([(L[i]>L[i-1]) for i in range(2,M+1)])])
M,N,n = 100,100,100000
l = []
for i in range(1,n):
View Hotels.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Hotels>
<Hotel Stars="****">
<Name>Harbor View Inn</Name>
<Contact>
<Phone>(805)963-0780</Phone>
<Email>contact@harborviewinn.com</Email>
</Contact>
<Address BusLines="R2">
<Number>28</Number>