Skip to content

Instantly share code, notes, and snippets.

from scoop import futures
import subprocess
import sys
def runApplication(number):
command = "opendcp_j2k -i in/{num:06d}.tiff -o out/{num:06d}.j2c"
return subprocess.call(command.format(num=number), shell=True)
if __name__ == "__main__":
returnValue = list(futures.map(runApplication, range(1, 172801)))
@soravux
soravux / euler1_s1.py
Last active December 15, 2015 23:08
Solution to the Project Euler problem #1 - For the multigrad blog (entry 1)
sum(x for x in range(1000) if x % 5 == 0 or x % 3 == 0)
@soravux
soravux / euler1_s1t.py
Last active December 15, 2015 23:08
Solution to the Project Euler problem #1 - For the multigrad blog (entry 1)
import timeit
timeit.timeit(
"sum(x for x in range(1000) if x % 5 == 0 or x % 3 == 0)",
number=10000
) / 10000.
@soravux
soravux / euler1_s2.py
Last active December 15, 2015 23:08
Solution to the Project Euler problem #1 - For the multigrad blog (entry 2)
# Algorithm
from itertools import chain
sum(set(x for x in chain(range(5, 1000, 5), range(3, 1000, 3))))
# To benchmark it
import timeit
timeit.timeit(
"sum(set(x for x in chain(range(5, 1000, 5), range(3, 1000, 3))))",
setup="from itertools import chain",
number=10000
@soravux
soravux / euler1_s3.c
Last active December 15, 2015 23:08
Solution to the Project Euler problem #1 - For the multigrad blog (entry 3)
#include <stdio.h>
unsigned int NumberIt()
{
/* Create a persistant variable x and initialize it to 0 */
static unsigned int x = 0;
for (x++; x < 1000; x++) {
if (x % 5 == 0 || x % 3 == 0) {
return x;
}
@soravux
soravux / euler1_s4.c
Last active December 15, 2015 23:09
Solution to the Project Euler problem #1 - For the multigrad blog (entry 4)
#include <stdio.h>
unsigned int x = 0, state = 0;
unsigned int NumberIt()
{
/* Create a persistant variable x and initialize it to 0 */
switch (state) {
/* case 0: Replaced by default*/
case 3:
@soravux
soravux / euler1_s5.c
Last active December 16, 2015 00:18
Solution to the Project Euler problem #1 - For the multigrad blog (entry 5)
#include <stdio.h>
#include <x86intrin.h>
#define NUMBER_OF_TRIES 1000000
int main()
{
register unsigned long lResult, lLoop, i;
for (lLoop = 0; lLoop < NUMBER_OF_TRIES; lLoop++) {
@soravux
soravux / euler1_s6.c
Last active December 19, 2015 11:58
Solution to the Project Euler problem #1 - For the multigrad blog (entry 6)
/* To compile with: gcc euler1_s6.c -nostartfiles -s -O3 -o euler1_s6 */
/* How many 3, 5 and 15 are there in 999 (below 1000) */
#define QTY3 ( 999 / 3 )
#define QTY5 ( 999 / 5 )
#define QTY15 ( 999 / 15 )
/* Their sums */
#define SUM3 ( 3 * ( QTY3 * (QTY3 + 1) / 2 ) )
#define SUM5 ( 5 * ( QTY5 * (QTY5 + 1) / 2 ) )
#define SUM15 ( 15 * ( QTY15 * (QTY15 + 1) / 2 ) )
/* The answer */
@soravux
soravux / async_sched.py
Last active December 20, 2015 06:08
Proof of concept asynchronous scheduler in Python
import time
import threading
import sched
import signal
class myAsyncSched(object):
"""Asynchronous scheduler"""
def __init__(self):
self.s = sched.scheduler(time.time, time.sleep)
@soravux
soravux / random_servo.py
Last active December 22, 2015 04:08
Code for the LCES from Multigrad's blog ( http://multigrad.blogspot.ca/ )
"""
Example of how to move randomly two servos plugged in the 5th and 6th channel
(slot 4 & 5) of a Pololu Micro Maestro 6.
This script requires pyserial.
"""
from random import randrange, uniform
from time import sleep
from struct import pack