Skip to content

Instantly share code, notes, and snippets.

@f0ster
f0ster / main.py
Created Aug 17, 2020
quantconnect wheel strategy example
View main.py
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@f0ster
f0ster / retryable.scala
Created Jun 28, 2019
Recursive Retryables in scala
View retryable.scala
import scala.concurrent.{ExecutionContext, Future}
trait Retryable {
// Returning T, throwing the exception on failure
@annotation.tailrec
final def retryDangerously[T](n: Int)(fn: => T): T = {
util.Try { fn } match {
case util.Success(x) => x
case _ if n > 1 => retryDangerously(n - 1)(fn)
case util.Failure(e) => throw e
@f0ster
f0ster / x.java
Created Feb 13, 2019
get android ad id
View x.java
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
AdvertisingIdClient.Info idInfo = null;
try {
idInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
@f0ster
f0ster / make_change.scala
Created Jul 24, 2018
more scala recursive fun
View make_change.scala
/**
* Exercise 3
*/
def countChange(money: Int, coins: List[Int]): Int = {
def count(m: Int, sortedCoins: List[Int]) : Int = {
if (sortedCoins.isEmpty) 0
else if (m - sortedCoins.head == 0) 1
else if (m - sortedCoins.head < 0) 0
else countChange(m - sortedCoins.head, sortedCoins) + countChange(m, sortedCoins.tail)
}
@f0ster
f0ster / balance.scala
Last active Jul 24, 2018
verifying balanced parens with recursion
View balance.scala
def balance(chars: List[Char]): Boolean = {
def balanced(chars: List[Char], currently_open_parens: Int): Boolean = {
if (chars.isEmpty) currently_open_parens == 0
else {
if(chars.head == '(') balanced(chars.tail, currently_open_parens+1)
else {
if(chars.head == ')' ) {
currently_open_parens > 0 && balanced(chars.tail, currently_open_parens-1)
} else balanced(chars.tail, currently_open_parens)
}
View Guardfile.rb
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
View method_logger.rb
module MethodLogger
def self.included(base)
methods = base.instance_methods(false) + base.private_instance_methods(false)
base.class_eval do
methods.each do |method_name|
original_method = instance_method(method_name)
Rails.logger.info "creating override method for #{method_name} #{base}"
define_method(method_name) do |*args, &block|
Rails.logger.info "-> #{base}##{method_name}(#{args.inspect})"
Rails.logger.info "-- #{block}"
View .eslintrc.json
{
"env":
{
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules":
{
"linebreak-style": ["error", "unix"],
@f0ster
f0ster / docker_WSL_volume_hack.sh
Created Aug 17, 2017
Using docker volumes in windows linux subsystem
View docker_WSL_volume_hack.sh
# Docker for Windows/Docker Machine is mounting C:\Users\ of your Windows to //c on the Docker host.
sudo touch /usr/local/bin/docker
sudo chmod +x /usr/local/bin/docker
cat EOF > /usr/local/bin/docker
#!/bin/bash
ARGS=`echo -n "$@" | sed -E 's/\/mnt\/([a-z])\//\/\/\1\//g'`
eval /usr/bin/docker $ARGS
EOF
## great success
@f0ster
f0ster / serverless.invoke.test.js
Created Aug 9, 2017
Wrapper to call serverless invokes with mock data, with execution wrapped with promises and tested with mocha
View serverless.invoke.test.js
// wire up exec for serverless invokes with mock test data event inputs
require('dotenv').load();
const exec = require('child_process').exec
, assert = require('assert')
const stream = require('stream');
const expect = require('chai').expect;