Skip to content

Instantly share code, notes, and snippets.

View nicholaskajoh's full-sized avatar
👨‍💻
Debugging

Nicholas Kajoh nicholaskajoh

👨‍💻
Debugging
View GitHub Profile
@nicholaskajoh
nicholaskajoh / pascal.py
Created November 5, 2016 16:50
Generate a Pascal triangle of n rows.
# pascal traingle generator - generates n rows of triangle
if __name__ == "__main__":
n = int(input("n: ")) # num rows
triangle = [] # pascal triangle
for x in range(0, n):
# no references for the 1's at the edges
# hard code them, generate the rest
if x == 0:
triangle.append([1])
@nicholaskajoh
nicholaskajoh / matrix.py
Created November 5, 2016 17:26
Matrix Calculator using Numpy
# matrix calculator
import numpy as np
if __name__ == "__main__":
# select matrix dimemsion
print("#### MATRIX CALCULATOR ####")
print("Paper work: ")
print("-- Separate row elements by spaces")
print("-- Use x to end matrix input")
print("-- Use only nxn matrices for non-arithmetic operations")
# Get the sum of a list of numbers without using a for loop
def add(arr, s = 0):
s += arr[0]
if len(arr) > 1:
s += add(arr[1:])
return s
print("Sum", add([1, 2, 3, 4, 5]))
# binomial coeficient
import math
if __name__ == "__main__":
print("#### Binomial Coefficent Calculator ####")
print("Use: Given (a + b)^n, p = coefficient of a, q = coefficient of b, t = nth term")
# get params n, p, q and t
n = int(input("n: "))
p = int(input("p: "))
@nicholaskajoh
nicholaskajoh / take_home.py
Created January 5, 2017 15:08
Fanan Kwanga's Take Home
def gradingSystem():
print("Enter 'done' to end program.")
score = input("Enter student's score between 0 to 100:")
while(score != "done"):
score = float(score)
if score >= 101 or score < 0:
print("Sorry, score out of grade system range")
elif score >= 90:
print("You got an 'A'")
elif score >= 80:
@nicholaskajoh
nicholaskajoh / ass_q2.py
Created January 5, 2017 15:30
Fanan Kwanga's Assignment Q2. Choose any method your like. I think M1 looks more mature and is faster.
import re
# method 1
# using Regular Expressions AKA RegEx-es
def lenFunction1():
print("#### Method 1 ####")
sentence = str(input("Enter valid sentence:"))
# use RegEx substitution
# param 1: find
# param 2: replace
@nicholaskajoh
nicholaskajoh / jquery.linky.js
Last active January 12, 2017 23:38
Hacked Andreas Savvides's jquery.linky to allow any link-to url + other tweaks.
/**
* jquery.linky.js v0.1.8
* https://github.com/AnSavvides/jquery.linky
* The MIT License (MIT)
*
* Copyright (c) 2013 - 2015 Andreas Savvides
*
* Customized to allow any link-to base url
* So you're not limited to Twitter, Instagram or GitHub
* Plus other hacks
@nicholaskajoh
nicholaskajoh / login_gui.py
Created January 24, 2017 07:43
Simple GUI Login System
# reference (https://pythonprogramming.net/change-show-new-frame-tkinter/)
import tkinter as tk
# window
class LoginApp(tk.Tk):
# constructor
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
.timeline {
position: relative;
padding:4px 0 0 0;
margin-top:22px;
list-style: none;
}
.timeline>li:nth-child(even) {
position: relative;
margin-bottom: 50px;
@nicholaskajoh
nicholaskajoh / form_submit.php
Created September 9, 2017 16:03
Form submission -- CDC
<?php
$fields = [];
$fields['name'] = $_POST['name'] ?? NULL;
$fields['sex'] = $_POST['sex'] ?? NULL;
$fields['q1'] = $_POST['q1'] ?? NULL;
$fields['q2'] = $_POST['q2'] ?? NULL;
$fields['q3'] = $_POST['q3'] ?? NULL;
// validation
$errors = [];