Skip to content

Instantly share code, notes, and snippets.

View nicksspirit's full-sized avatar
❤️
Currently in a committed relationship with python

Nick Muoh nicksspirit

❤️
Currently in a committed relationship with python
View GitHub Profile
@nicksspirit
nicksspirit / find_seq_in_array.py
Created June 5, 2017 03:27
Given an array of ints, return True if the sequence.. 1, 3, 4 .. appears in the array somewhere.
# This method should be pretty clear
# it runs in O(n) time since I am going through the array of ints once
# it ONLY returns true if it succesfully finds the first occurence of my seq in the array of ints
def find_in_seq(array, seq_to_find):
# Track what has been popped
popped = []
len_of_seq = len(seq_to_find)
@nicksspirit
nicksspirit / .bash_profile
Created December 18, 2017 07:52 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@nicksspirit
nicksspirit / replacer.py
Last active September 3, 2018 22:14
replace multiple substrings in a string.
from functools import reduce
# Lets define a helper method to make it easy to use
def replacer(text, replacements):
return reduce(
lambda text, ptuple: text.replace(ptuple[0], ptuple[1]),
replacements, text
)
@nicksspirit
nicksspirit / composer.py
Last active February 23, 2018 20:01
Create a compose function similar to rambda.js's compose function
from functools import reduce, partial
import random
import math
def calcMean(iterable):
return sum(iterable) / len(iterable)
def formatMean(mean):
@nicksspirit
nicksspirit / RockPaperScissors.cpp
Last active May 14, 2018 08:44
A simple Rock Paper Scissors game made in C++
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <map>
#include <string>
int randMove() {
return std::rand() % 3;
}
@nicksspirit
nicksspirit / binary_tree_traversal.py
Last active August 21, 2022 05:07
Binary tree implementation with python generators & dataclasses.
from dataclasses import dataclass
from typing import Any
@dataclass
class EmptyNode:
data: Any
def __iter__(self):
return self.__generator__()
@nicksspirit
nicksspirit / decorator_in_class.py
Last active December 29, 2019 03:50
Creating a decorators that belong to the class.
from functools import wraps
class _Decorator:
""" Class Decorators"""
@classmethod
def func(cls, arg):
def wrapper(fn):
@wraps(fn)
def wrap(self, *args, **kwargs):
@nicksspirit
nicksspirit / falcon_multipart.py
Last active July 22, 2019 08:50
A middleware for falcon, python web framework, to handle multipart form requests. It stores files in `Request.files` and other form parameters in `Request.form_params`
FieldValue = Union[FieldStorage, str]
class MultipartMiddleware(Middleware):
MEDIA_FORM = "multipart/form-data"
METHODS_ALLOWED = {"PUT", "POST"}
def _get_field_val(self, field: FieldStorage) -> FieldValue:
"""
Returns input value for input text fields and FileStream object
"""
@nicksspirit
nicksspirit / hide-dots.ps1
Created January 13, 2020 15:23
Hide files with a dot infront of them on windows
function Hide-Dots {
Param(
[Parameter(Position=0)]
[ValidateScript({ Test-Path $_ })]
[string] $path="."
)
if ($path -eq ".") {
$cwd = (Get-Location).Path.Substring((Get-Location).Path.LastIndexOf("\") + 1)
echo "Searching for files in $($cwd) ..."
@nicksspirit
nicksspirit / goFullScreen.js
Created January 24, 2020 16:31
Javascript function that uses the Full Screen API to display an element in fullscreen.
goFullScreen() {
const fullScreenPrefixes = [
'requestFullscreen',
'webkitRequestFullscreen',
'mozRequestFullScreen',
'msRequestFullscreen'
]
// HTMLElement is the DOM element you want to make full screen
const prefixedFn = fullScreenPrefixes.find(
prefixedFn => HTMLElement[prefixedFn] !== undefined