Skip to content

Instantly share code, notes, and snippets.

View SlyCodePanda's full-sized avatar
🤖
Working

Renee Marsland SlyCodePanda

🤖
Working
View GitHub Profile
@SlyCodePanda
SlyCodePanda / decorators_01.py
Last active May 27, 2019 14:38
A step-by-step of how decorators work in Python (ref: Decoding the mysterious Python Decorator - Preyansh Shah)
'''
Functions can return other functions.
Lets look at an example of how inner functions can use the enclosing scope of the outer function.
Known in Python as "Closure".
'''
def outer_func(name):
def inner_func():
return "We are using the name {} inside inner_func".format(name)
return inner_func
@SlyCodePanda
SlyCodePanda / emptyPyQtApp.py
Last active April 12, 2019 07:55
Stuff for PyQt quick creations
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self,parent)
self.initUI()
@SlyCodePanda
SlyCodePanda / findingPercentage.py
Created December 19, 2018 04:31
Learning to use pytest with a HackerRank challenge.
def main():
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
result = sum(student_marks[name])/n
@SlyCodePanda
SlyCodePanda / CrapsSimulation.py
Created June 6, 2018 07:08
Simulates 5000 games of Craps and works out the probability of winning a game, and the average number of times the dice is rolled per game.
from __future__ import division
import random
numRolls = 0 # Number of times the dice is rolled.
# generates a random number between 1 and 6, like rolling a 6 sided die.
def rollDice() :
return random.randint(1, 6)
# Simulate this 5000 times, then to get the prob of winning, do (numb of times won/numb of times simumalted).
@SlyCodePanda
SlyCodePanda / binaryConverter.cpp
Last active May 3, 2018 02:39
Base10 to Base2 Converter
#include <iostream>
#include <bitset>
using namespace std;
// Convert base 10 number to base 2.
string binary(int num)
{
bitset<16> bin(num);
string binrayString = bin.to_string();