Skip to content

Instantly share code, notes, and snippets.

View jonasschneider's full-sized avatar

Jonas Schneider jonasschneider

View GitHub Profile
import numpy
from numpy import argsort, mean, std
def sample_norm(mu, sigma):
return numpy.random.normal(loc=mu, scale=sigma)
def sample_norm_vec(mu, sigma, len):
return [sample_norm(mu, sigma) for i in range(0, len)]
def cem(f, mu0, sigma0, n_iter, n_samples, p_elite, noise_amount):
extern crate tls;
extern crate byteorder;
extern crate openssl;
extern crate crypto;
use std::fs::File;
use std::io::{Read,Write,Cursor};
use std::net::TcpListener;
extern crate tls;
extern crate byteorder;
extern crate openssl;
extern crate crypto;
use std::fs::File;
use std::io::{Read,Write,Cursor};
use std::net::TcpListener;
EXPLAIN UPDATE participants dest_participants SET seqno =
(SELECT n FROM
(SELECT participants.id id, row_number() OVER (PARTITION BY projects.account_id ORDER BY participants.id) n
FROM participants JOIN projects ON participants.project_id=projects.id)
t WHERE t.id=dest_participants.id)
WHERE dest_participants.seqno IS NULL;
QUERY PLAN
---------------------------------------------------------------------------------------------------------
Update on participants dest_participants (cost=0.00..6895397.53 rows=438 width=336)
@jonasschneider
jonasschneider / README.md
Last active August 29, 2015 14:20
Platform differences on subshell invocation using Ruby's exec

The following test case illustrates an unexpected behaviour of of Ruby's Kernel#exec call caused by platform differences between OS X and Linux.

In both tests, a program is spawned that simply prints all the process IDs of its ancestors. From this list, the list of the ancestors of the test process is substracted, so the list only contains ancestors added by the exec invocation.

In the first test, the comand line /path/to/program is Kernel#exec'd. This works on both platforms. However, the second test tries to exec the command line '/path/to/program' (note the quotes). This leads to a platform difference: while on OS X, just one new ancestor is created, Linux creates two.

The root cause is likely an implementation difference between OS X's and Linux's sh program. Even if you just give it a single absolute path to an executable file, Ruby will always spawn a subshell if you pass just one argument to Kernel#exec. Both shells, if given an exact absolute path, will directly exec(2) (or whatever

[http-bio-8080-exec-7] ERROR spark.webserver.MatcherFilter -
java.lang.NullPointerException
at edu.kit.ipd.creativecrowd.persistentmodel.PersistentAnswer.equals(PersistentAnswer.java:156)
at edu.kit.ipd.creativecrowd.operations.SubmitAssignmentTransaction.run(SubmitAssignmentTransaction.java:54)
at edu.kit.ipd.creativecrowd.connector.Connector.submit(Connector.java:188)
at edu.kit.ipd.creativecrowd.controller.AssignmentController.update(AssignmentController.java:124)
at edu.kit.ipd.creativecrowd.router.Router.lambda$10(Router.java:89)
at edu.kit.ipd.creativecrowd.router.Router$$Lambda$11/881848365.handle(Unknown Source)
at spark.SparkBase$1.handle(SparkBase.java:264)
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:154)
ubuntu@ip-172-31-15-61:~$ sudo jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=5996
Initializing jdb ...
> threads
Group system:
(java.lang.ref.Reference$ReferenceHandler)0xd0 Reference Handler cond. waiting
(java.lang.ref.Finalizer$FinalizerThread)0xcf Finalizer cond. waiting
(java.lang.Thread)0xcd Signal Dispatcher running
(sun.misc.GC$Daemon)0xcc GC Daemon cond. waiting
Group main:
(java.lang.Thread)0xd1 main running
@jonasschneider
jonasschneider / gist:2aa3f41f989282980cdf
Created April 25, 2015 23:47
Why does gdb return the (correct) 44, but python the wrong 45, which doesn't even exist?
$ sudo gdb --batch --pid 4899 -ex "print /s ptsname(12)"
0x00007fb15b9faf20 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
81 ../sysdeps/unix/syscall-template.S: No such file or directory.
$1 = 0x7fb15bcfd9d0 <buffer> "/dev/pts/44"
$ test/scripts/uml-ptsname /proc/4899/fd/12
/dev/pts/45
$ cat test/scripts/uml-ptsname
#!/usr/bin/python
@jonasschneider
jonasschneider / -
Created March 20, 2015 22:24
Simple arduino compatibility layer :)
void digitalWrite(const uint8_t pin, const uint8_t val) {
}
uint8_t digitalRead(const uint8_t pin) {
return 0;
}
/**
******************************************************************************
* @file system_stm32f4xx.h
* @author MCD Application Team
* @version V2.3.0
* @date 02-March-2015
* @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
******************************************************************************
* @attention
*