Skip to content

Instantly share code, notes, and snippets.

View alf239's full-sized avatar

Alexey Filippov alf239

  • Cambridge, UK
View GitHub Profile
@alf239
alf239 / ib.nb
Last active September 2, 2018 19:11
Needs["JLink`"];
ReinstallJava[
ClassPath -> "C:\\TWS_API\\source\\JavaClient\\TwsApi.jar"];
LoadJavaClass["com.ib.client.Types$MktDataType"];
LoadJavaClass["com.ib.client.TickType"];
myAccounts := {};
SetSharedVariable[myAccounts];
@alf239
alf239 / BSM basics.ipynb
Created April 16, 2017 21:16
First steps in IHaskell
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
object Direction extends Enumeration {
type Direction = Value
val NORTH, EAST, SOUTH, WEST, NONE = Value
def getFromShortName(shortName: Char): Direction = shortName match {
case 'N' => NORTH
case 'E' => EAST
case 'S' => SOUTH
case 'W' => WEST
case _ => NONE
@alf239
alf239 / fizzbuzz.hs
Last active December 20, 2015 10:39
Fizz/Buzz
import Data.List
fizzbuzz :: Int -> String
fizzbuzz i
| divisibleBy 15 = "FizzBuzz"
| divisibleBy 5 = "Buzz"
| divisibleBy 3 = "Fizz"
| otherwise = show i
where divisibleBy = (==) 0 . mod i
@alf239
alf239 / robot.py
Created November 5, 2012 10:52
Genetic algorithm for a 7-form home task
#!/usr/bin/env python
# encoding: utf-8
"""
robot.py
Created by Alexey Filippov on 2012-11-03.
Copyright (c) 2012 Alexey Filippov. All rights reserved.
"""
import sys
@alf239
alf239 / Deadlock.java
Created January 16, 2012 13:47
Deadlock in Java
public class Deadlock implements Runnable {
private final Object a;
private final Object b;
private final static CountDownLatch latch = new CountDownLatch(2);
public Deadlock(Object a, Object b) {
this.a = a;
this.b = b;
}
@alf239
alf239 / Chain.java
Created January 7, 2012 16:52
Chained method invocation VS JavaBeans introspection
package org.acm.afilippov;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class Chain {
private int i;
public int getI() {
public class VolatileExample implements Runnable {
public static boolean flag = true; // do not try this at home
public void run() {
long i = 0;
while (flag) {
if (i++ % 10000000000L == 0)
System.out.println("Waiting " + System.currentTimeMillis());
}
}
@alf239
alf239 / version.groovy
Created November 29, 2011 13:14
Get git version
def env = System.getenv()
def gitcmd = "git"
if (env["com.apple.java.jvmMode"])
gitcmd = "/usr/local/git/bin/git"
if (env["OS"] =~ /^Windows/)
gitcmd = "cmd /c ${gitcmd}"
def gitDescribe = """${gitcmd} describe""".execute().in.text.trim()
def m = gitDescribe =~ /(?:atlas-)?(.*)/
def gitBranch = """${gitcmd} symbolic-ref -q HEAD""".execute().in.text.trim()
@alf239
alf239 / autohider.user.js
Created November 8, 2011 23:26
Autohider in JS
$.each(
$.grep(
$(".l_expandcomments"),
function(e) {
var m = /(\d+) more comments/.exec(e.innerHTML);
return m && parseInt(m[1]) > 10;
}),
function() {
$(".l_hideone", $(this).parents(".l_entry"))
.click();