Skip to content

Instantly share code, notes, and snippets.

View Nydhal's full-sized avatar
🎯
Focusing

Nidhal Selmi Nydhal

🎯
Focusing
View GitHub Profile
Verifying that +nidhalselmi is my blockchain ID. https://onename.com/nidhalselmi
@Nydhal
Nydhal / bubble.c
Last active November 21, 2017 18:00
bubble sort in C
void sortStrings(char strings[NUM_STRINGS][STRING_LENGTH]){
for (int i = 0; i < NUM_STRINGS-1 ; i++){
for (int j = 0; j < NUM_STRINGS-i-1; j++){
if (strcmp(strings[j],strings[j+1])>0) {swapStrings(strings[j], strings[j + 1]);
}}}}
@Nydhal
Nydhal / queue.cpp
Last active November 12, 2021 04:47
Queue Class example with explanations in C++
#include <iostream>
using namespace std;
class Queue { // Class definition
private: //private members can only be accessed in the class
int queue_size;
protected: // protected members can ba accessed in derived classes
int* buffer; // pointer to first element of array
int front; // used for removing an element of array
int rear; // user for adding an element into queue
@Nydhal
Nydhal / quick_sort.py
Last active November 21, 2017 17:59
CLRS introduction to algorithms Quicksort with decision tree outputs
## Quicksort
def swap(array,i,j):
temp = array[i]
array[i] = array[j]
array[j] = temp
def partition(array, start,end):
print('->P(',start,end,')')
x = array[end]
@Nydhal
Nydhal / perceptron_test.py
Created November 13, 2017 00:46
Simple perceptron neural net to test boolean functions (CSE471).
import math
def sig(x):
return 1 / (1 + math.exp(-x))
b = [0,1]
# INPUT WEIGHTS #
w1 = [ 2, 1,-3,-4,-4, 4]
@Nydhal
Nydhal / auto_sparky.py
Created November 21, 2017 17:59
code snippet for /r/place to draw ASU sparky
import math
import sys
import time
import random
import requests
from PIL import Image
from requests.adapters import HTTPAdapter
img = Image.open(sys.argv[1])
<?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>
@Nydhal
Nydhal / run_calc.py
Last active April 26, 2018 04:55
#Python code to sample n trials given N and M (short but not best way) https://twitter.com/CutTheKnotMath/status/989147356129058816
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):
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 / audio.html
Last active July 6, 2018 00:40
Stylized HTML5 audio player
<!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>