Skip to content

Instantly share code, notes, and snippets.

View martinandersson82's full-sized avatar

martinandersson82

View GitHub Profile
import random
def binary_search(input_list , target_value):
'''
Function executing binary search to find if element is in a list.
parameters:
- list
- target
return value: True/False (bool)
def list_elements_sum(input_list , sum_check):
#list to store complements
complements = []
for index,value in enumerate(input_list):
#get complement for current value
check_sum = sum_check-value
#if value is in complements list we found our match
if value in complements:
def list_elements_sum(input_list , sum_check):
#loop through the list
for index,value in enumerate(input_list):
#we don't want to work with the last index as it is covered
if index != (len(input_list)-1):
#sum loop element with the rest of the list
for inner in range(index+1, len(input_list)):
add_item = input_list[inner]
sum_current = value + add_item
import os
import pathlib
def get_file_exts(directory):
#list all files in directory:
search_path = pathlib.Path(directory).iterdir()
file_list = [file.name for file in search_path if file.is_file()]
#create a new list with tuple pairs of the filename and extension for all files:
import maya.cmds as cmds
list_cameras = cmds.listCameras()
cam_list = [cam for cam in list_cameras if not cmds.camera(cam, q=True, startupCamera=True)]
for cam in cam_list:
print(cam)
#tabulate to output a nice table of the menu items
from tabulate import tabulate
class Menu():
def __init__(self,header,item_container=[]):
self._header = header
self._item_container = item_container
def add_item(self,item):
class Food():
def __init__(self,name,price,ingredients=[],allergens=[]):
self._name = name
self._price = price
self._ingredients = ingredients
self._allergens = allergens
def add_ingredient(self,ingredient):
import sys
from zipfile import ZipFile
from datetime import datetime
import os
from pathlib import Path
import shutil
def get_file_path(filename):
'''
function returning the full path of the file passed
@martinandersson82
martinandersson82 / main.py
Last active August 10, 2020 22:56
a publish system
import os
def publish(search_path):
print(f'working on: {search_path}')
#list folders in search path
scan_search_path = [folder.name for folder in os.scandir(search_path) if folder.name != '.DS_Store']
#if there is a work folder available, we can start working
if 'work' in scan_search_path:
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.label import Label