Skip to content

Instantly share code, notes, and snippets.

defmodule Rebalancex do
alias Rebalancex.Quote
@underweight 0.25
@overweight 0.27
def rebalance_portfolio(allocations, quote_service \\ Quote) do
portfolio = %{cash: 0, allocations: allocations}
prices = get_prices(allocations, quote_service)
allocations = %{"IAU" => 10, "TLT" => 10, "VGSH" => 10, "VTI" => 10}
orders = Rebalancex.rebalance_portfolio(allocations)
@elvio
elvio / user.html
Last active August 29, 2015 14:27
User events sample for Foxplan (http://www.github.com/elvio/foxplan)
<html>
<head>
<script>
var ws = new WebSocket("ws://localhost:8080/ws/mobile");
function formatMessage(m) {
return JSON.stringify(m);
}
function joinRoom(code) {
@elvio
elvio / room.html
Created August 10, 2015 08:54
Room events sample for Foxplan (http://www.github.com/elvio/foxplan)
<html>
<head>
<script>
var ws = new WebSocket("ws://localhost:8080/ws/web");
function formatMessage(m) {
return JSON.stringify(m);
}
function roomCreate() {
@elvio
elvio / map-reduce.js
Created August 12, 2014 08:50
Map Reduce with published_at limit
var mapFunction = function() {
emit(this.facebook_object_id, 1);
};
var reduceFunction = function(key, values) {
return Array.sum(values);
};
var options = {
query: {published_at: {$gt: new Date(2013, 1, 1)}},
@elvio
elvio / interactions_map_reduce.js
Created August 11, 2014 14:37
Simple Mongo map-reduce
var mapFunction = function() {
emit(this.facebook_object_id, 1);
};
var reduceFunction = function(key, values) {
return Array.sum(values);
};
var options = {
out: {inline: 1},
@elvio
elvio / gist:7689361
Created November 28, 2013 09:31
Ubuntu Locale fix
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
This file has been truncated, but you can view the full file.
var suiteHistory = [{"suiteId":1,"size":120232,"price":324845,"createdAt":1240012800000,"availableAt":null},{"suiteId":1,"size":22250,"price":525868,"createdAt":1247788800000,"availableAt":null},{"suiteId":1,"size":78625,"price":520289,"createdAt":1260230400000,"availableAt":1260230400000},{"suiteId":1,"size":224437,"price":158011,"createdAt":1242000000000,"availableAt":1242000000000},{"suiteId":1,"size":102712,"price":413818,"createdAt":1237852800000,"availableAt":null},{"suiteId":2,"size":192924,"price":306493,"createdAt":1260921600000,"availableAt":null},{"suiteId":2,"size":294399,"price":258054,"createdAt":1256256000000,"availableAt":null},{"suiteId":2,"size":208816,"price":267297,"createdAt":1236211200000,"availableAt":null},{"suiteId":2,"size":261484,"price":499823,"createdAt":1240531200000,"availableAt":null},{"suiteId":2,"size":267668,"price":472518,"createdAt":1252800000000,"availableAt":1252800000000},{"suiteId":3,"size":36096,"price":276294,"createdAt":1240012800000,"availableAt":null},{"suiteId":3
@elvio
elvio / spec_helper.rb
Created September 18, 2013 13:05
Disable RSpec old syntax
RSpec.configure do |config|
# ...
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
def all
grouped.map do |provider, sources|
{name: provider, priority: priority_for(provider), offers: offers(sources)}
end.sort_by {|i| i[:priority]}.reject {|i| self.blacklist.include?(i[:name])}
end
def blacklist
if client.version < 2.6
@blacklist ||= [Amazon Maxdome, Google Play, Xbox, Mediamarkt, Videoload, Videobuster]
elsif is_landing_page