Skip to content

Instantly share code, notes, and snippets.

View konstantinfarrell's full-sized avatar

Konstantin Farrell konstantinfarrell

View GitHub Profile
@konstantinfarrell
konstantinfarrell / fizzbuzz.py
Created June 28, 2016 20:42
FizzBuzz one-liner in Python 3
# Using a lambda function
print(list(map(lambda i: "Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i), range(1,101))))
# Using a for loop
for i in range(1, 101): print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i))
@konstantinfarrell
konstantinfarrell / foo.js
Last active September 5, 2019 20:33
Google scraper stuff
var scraper = require("google-play-scraper")
// get a list of apps
var apps = scraper.search({
term: "foo",
num: 100,
})
var meta = []
@konstantinfarrell
konstantinfarrell / web.html
Last active September 9, 2017 21:15
A neat graph/web animation using p5.js
<!DOCTYPE html>
<html>
<head>
<title>Webs</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.14/p5.js"></script>
<style>
body {
margin: 0;
overflow-x: hidden;
overflow-y: hidden;
@konstantinfarrell
konstantinfarrell / fix_massive.py
Last active March 11, 2017 18:58
Is Massive broken because of that stupid database file? Use this. Python 3.6
import os
def fix_massive():
user = os.getlogin()
shit = rf'C:\Users\{user}\AppData\Local\Native Instruments\Massive\NIMassiveDataBase_ul'
if os.path.exists(shit):
os.remove(shit)
@konstantinfarrell
konstantinfarrell / organize_directory.py
Created May 29, 2016 22:18
Python script that cleans up my downloads folder
import shutil
import mimetypes
from os import listdir
from os.path import isfile, join
ORIGIN = r"C:\Users\Konstantin\Downloads\\" # Change these. Unless your system
# happens to have the same configuration.
MUSIC_DESTINATION = r"C:\Users\Konstantin\Music\\"
PICTURE_DESTINATION = r"C:\Users\Konstantin\Pictures\\"
PDF_DESTINATION = r"C:\Users\Konstantin\Documents\\"
@konstantinfarrell
konstantinfarrell / golevel.py
Last active July 7, 2016 19:01
What originally was meant to be a quick script to determine how much total XP is needed to reach a certain level turned into an exercise showing the value of knowing the summation formula rather than simply going for the brute-force method
import timeit
import math
def total_xp(level):
"""
Uses a loop to compute the total amount of xp
needed to reach a certain level.
"""
total = 0
@konstantinfarrell
konstantinfarrell / directory_walk.py
Last active July 3, 2016 21:28
Recursive directory walk function in Python.
import os
def directory_walk(path):
for item in os.listdir(path):
if os.path.isdir(item):
directory_walk(item)
else:
print(item)
import os
def fibonnacci(num):
"""
Takes a number num and returns the num'th fibonnacci number.
"""
if num == 2 or num == 1:
return 1
else:
fib = fibonnacci(num-1) + fibonnacci(num-2)
@konstantinfarrell
konstantinfarrell / stock_request.py
Last active June 14, 2016 06:47
Query a stock symbol with the python requests library
import requests
API_URL="http://finance.yahoo.com/d/quotes.csv"
symbol="AMZN"
params="sopc"
querystring = API_URL + "?s=" + symbol + "&f=" + params
@konstantinfarrell
konstantinfarrell / cube_error.ino
Created May 14, 2016 00:39
Arduino code to translate HTTP error messages into LED patterns on a 3x3x3 LED matrix.
// we're gonna try something new here.
int scannow=0,scandir=0;
int incoming = 0;
unsigned int table[][4]={
{0x000, 0x000, 0x000, 0x0000},
};
void setup() {
Serial.begin(9600);