Skip to content

Instantly share code, notes, and snippets.

View krissrex's full-sized avatar
🏢
Working from Capra HQ

Kristian Rekstad krissrex

🏢
Working from Capra HQ
View GitHub Profile
@krissrex
krissrex / Print function caller's classname, method and line number.
Created August 6, 2014 11:34
Call the member a member function to output where it was called from. Could be used in debugging control flow.
package com.polarbirds.debug;
/**
* No licence; public domain.
* @author krissrex
*/
public class DebugPrint {
/**
* For testing
@krissrex
krissrex / ncpc 2013 A
Created September 29, 2014 18:57
algoritme for oppg A. (mangler innlesing fra fil)
b = [39, 39, 38, 35,20,9]
ind = 0
day = 1
while True:
day += 1
for i in range(ind):
b[i] -= 1
if ind < len(b):
ind += 1
@krissrex
krissrex / long_seq.py
Last active August 29, 2015 14:10
Longest sequence
def longestSeqLen(array):
return len(max("".join(str(i) for i in array).split("0"), key=lambda x: len(x)))
def longest_seq_index_and_len(array):
longest = max("".join(str(i) for i in array).split("0"), key=lambda x: len(x))
return ("".join(str(i) for i in array)).find(longest), len(longest)
def readble_version(array):
# [1,0,0,1,1] -> ['1', '0', '0', '1', '1']
@krissrex
krissrex / random_number_list.py
Last active August 29, 2015 14:10
Harr harr
import random
def rand(n):
a = list(range(n+1))
b = []
while len(a):
i = random.randint(0, len(a)-1)
b.append(a[i])
del a[i]
return b
z/x for octave down/up. q to quit.
Notes from c to h:
cCdDefFgGaAh
and 0 means pause.
Enter notes (note[duration]):
cdefg2g2aaaag4ffffe2e2ddddc4q
Parsing: c
Note: freq:261 duration:1 octave:4
Parsing: d
@krissrex
krissrex / CountryCodeExtractor.java
Created January 23, 2015 19:53
landskoder.txt er en tabell hentet ut fra kildekoden til http://countrycode.org/
package tdt4100.encapsulation.util;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@krissrex
krissrex / androidify_icons.py
Created July 8, 2015 00:30
Android file renamer
import os, shutil
def list_files():
files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.png')]
print(files)
return files
def find_out():
out_folder = 'out'
counter = 0;
@krissrex
krissrex / rxjavaexperiments_Main.java
Created September 15, 2015 21:00
RxJava test with JavaFX
package com.polarbirds.rxjavaexperiments;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@krissrex
krissrex / parse.py
Last active December 5, 2021 19:29
PSON - Python Script Object Notation
def read(path):
with open(path) as f:
return "".join(f.readlines())
def tokenize(str):
out = []
str = str.strip()
str = str.strip("{").strip("}")
str = str.split(",\n")
for kv in str:
#include "Blackjack.h"
#include <algorithm> // min
#include <iostream>
// Unnamed namespace for liten util-function i 5d
namespace {
int askForAceValue()
{
int value = -1;
while (!(value == 1 || value == 11))