Skip to content

Instantly share code, notes, and snippets.

View OskarSigvardsson's full-sized avatar

Oskar Sigvardsson OskarSigvardsson

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Order</title>
<style type="text/css">
body {
margin: 40px auto;
max-width: 650px;
line-height: 1.6;
font-size: 18px;
@OskarSigvardsson
OskarSigvardsson / Tester.cs
Last active July 26, 2017 16:03
Sets of three common numbers benchmark
using System;
using System.Diagnostics;
using System.Collections.Generic;
public class Tester {
public static void Main() {
var count = 1000000;
var tris0 = new int[count * 3];
var tris1 = new int[count * 3];
@OskarSigvardsson
OskarSigvardsson / maxsubarr.py
Created May 9, 2015 22:45
Maximum subarray problem demonstration
def max_of_array_ending_at(array, p):
if p == 0:
return array[0] if array[0] > 0 else 0
subproblem = max_of_array_ending_at(array, p-1)
if subproblem + array[p] > 0:
return subproblem + array[p]
else:
autocmd!
"Start pathogen
execute pathogen#infect()
"Recognize filetypes and indentation
filetype indent on
"Turn on syntax highlighting
syntax on
from math import sqrt
def is_prime(n):
for divisor in range(2, int(sqrt(n))+1):
if n % divisor == 0:
return False
return True
ACT I.
SCENE I. An open place.
[An open place. Thunder and lightning. Enter three Witches.]
FIRST WITCH.
When shall we three meet again
In thunder, lightning, or in rain?
SECOND WITCH.
On day 2014-11-06
05:18 am to 06:00 am -- code review
06:16 am to 07:32 am -- food
07:51 am to 08:25 am -- personal appointment
08:53 am to 09:55 am -- workout
10:32 am to 11:22 am -- sales call
11:29 am to 00:18 pm -- code review
00:18 pm to 01:30 pm -- reddit
01:30 pm to 01:59 pm -- sales call
02:47 pm to 03:23 pm -- work
>>> pattern = "(([A-Z]{2}-){2}\d{2,3})|([A-Z]{2}-\d{4})"
>>> string = "GS-0214"
>>> import re
>>> re.match(pattern, string)
<_sre.SRE_Match object; span=(0, 7), match='GS-0214'>
def calc_pi(n):
s = 0
sign = 1
for i in range(n):
n = i*2 + 1 # n will be an odd number
s += sign * 1.0/n
sign *= -1
def factors(n):
factors = []
# This loop weeds out any factors of 2 that are in the number
while n % 2 == 0:
factors.append(2)
n //= 2
# This variable holds the divisor that we're testing