Skip to content

Instantly share code, notes, and snippets.

View trylks's full-sized avatar
🤖
Automating

trylks trylks

🤖
Automating
View GitHub Profile
@trylks
trylks / MACDCalculator.java
Created January 31, 2012 12:04
MACD calculator. Not a standalone Java program but some Java code as good as pseudocode.
import java.util.ArrayList;
public class MACDCalculator extends SimpleCalculator {
private float ema1alpha;
private float ema2alpha;
private float signalalpha;
private float[] pema1;
private float[] pema2;
private float[] psignal;
@trylks
trylks / macd_aggregator.sql
Created January 31, 2012 19:52
Here is a brief pl/pgsql code to calculate the MACD indicator from a table storing daily candles. It's not finished and help is welcome, either wrt efficiency or wrt correctness, for some reason EMA formulas online are calculated with alpha [0,1] whereas
create table candles(ticker text, day date, value real, primary key (ticker, day));
drop table macdtuple cascade;
CREATE TABLE macdtuple (ticker real, ema1val real, ema2val real, signalval real);
create or replace function macd_tuple_func(state macdtuple, inval real, ticker real, alpha1 real, alpha2 real, alpha3 real) returns macdtuple as $previousmacd$
declare
x macdtuple;
begin
if (state is null OR ticker <> ticker(state)) then
@trylks
trylks / makegal.py
Created February 1, 2012 17:18
This is an ad-hoc script I made time ago to generate an image gallery, it's meant to be run on a folder that contains folders that contain the images. No more or less nesting. The style may be from somewhere, contact me to remove or cite source.
import Image, os, sys, os.path
#hardcoded constants
stdside = 200
title = "Title"
header = '<html><head><title>%s - %s</title><style type="text/css">img{margin: 12px; padding: 8px;background: white;border: 1px solid #CCC;\
-moz-box-shadow: 0 0 20px rgba(0, 0, 0, .2);-webkit-box-shadow: 0 0 20px rgba(0, 0, 0, .2);box-shadow: 0 0 20px rgba(0, 0, 0, .2);\
-moz-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;}</style></head><body>'
footer = '</body></html>'
template = '<a href="%s"><img src="%s"/></a>'
@trylks
trylks / randomsum.py
Last active October 5, 2015 19:38
Generate sum of many random numbers, functional style.
#!/usr/bin/env python3
#it's about this: http://inecas.posterous.com/a-bit-about-functional-style-in-ruby-clojure
from functools import reduce
from random import random
from operator import add
print(reduce(add, map(lambda x: random(), range(10000000))))
print(sum(map(lambda x: random(), range(10000000))))
print(sum([random() for _ in range(10000000)]))
@trylks
trylks / test.html
Last active December 17, 2015 18:39
Google docs gave me some code I'm not sure where to put.
<html><head><title>This is a test</title></head><body><script type="text/javascript" src="http://ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js"> {"dataSourceUrl":"http://docs.google.com/spreadsheet/tq?key=0AvfclSzBscS6dF96aVo5eEpKWEVETS1iS2dyNzBrMmc&transpose=1&headers=1&range=A2%3AN4&gid=0&pub=1","options":{"vAxes":[{"useFormatFromData":true,"minValue":null,"viewWindow":{"min":null,"max":null},"maxValue":null},{"useFormatFromData":true,"minValue":null,"viewWindow":{"min":null,"max":null},"maxValue":null}],"displayAnnotations":true,"titleTextStyle":{"fontSize":16},"booleanRole":"certainty","title":"T\u00edtulo del gr\u00e1fico","animation":{"duration":0},"legend":"right","hAxis":{"useFormatFromData":true,"minValue":null,"viewWindow":{"min":null,"max":null},"maxValue":null},"wmode":"opaque","width":608,"height":397},"state":{},"view":{},"isDefaultVisualization":true,"chartType":"AnnotatedTimeLine","chartName":"Gr\u00e1fico 1"} </script></body></html>
@trylks
trylks / tailrecmaxcomparable
Created August 6, 2013 13:10
I'm still learning Scala so this may be very wrong for a number of reasons. I'm not even sure about the meaning of the <: operator
// for: http://stackoverflow.com/questions/14011181/how-can-i-find-the-index-of-the-maximum-value-in-a-list-in-scala
@tailrec
final def maxindex[T <: Ordered[T]](list:Iterable[T], defaultIndex:Int = -1, defaultValue:T=None, currentIndex:Int = 0):(Int, T) = list match {
case Nil => (defaultIndex, defaultValue)
case head::tail =>
if (head > defaultValue)
maxindex(tail, currentIndex, head, currentIndex+1)
else
maxindex(tail, defaultIndex, defaultValue, currentIndex+1)
@trylks
trylks / longreply.md
Created September 16, 2013 18:17
This is a very long reply, so I needed somewhere else to write it.

This is a reply to a comment in philosophy@stackexchange, but to some extent it's self-contained and definitively quite long.

If photons actually behave like a wave or not doesn't matter for the point I'm trying to make. The model could simply be imprecise without hidden variables. For instance photons could be like a sphere rotating inside a greater sphere (that we call photon, even though it's just a boundary for the true photon), therefore the inner sphere would work like the wave I'm talking about. Photons could be composed of subparticles that could be moving in the photon in such a way that could explain this behaviour, and in this way we can find many other possible explanations. Randomness, on the other hand, cannot be explained, randomness is the lack of explanation, the lack of cause, it cannot be verified.

About Bell experime

@trylks
trylks / commands.tex
Last active August 29, 2015 14:02
Automatic paper description
% Simply this:
% write \contents{whatever} to add that to the description and write \listofstructure{} to show the description. That's everything.
\newcommand{\listofstructure}{\InputIfFileExists{toc.toc}{}}
\newcommand{\contents}[1]{\immediate\write\delayedtext{In section\unexpanded\expandafter{~}\arabic{section} #1. }}
\AtBeginDocument{\newwrite\delayedtext
\immediate\openout\delayedtext=toc.toc.aux
package main
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
object NCApp {
def main(args: Array[String]) = {
val l = 1 to 100
@trylks
trylks / Allocate.scala
Last active August 29, 2015 14:06
Programming kata suggested by a friend, formulation not available at this moment.
package main
import collection.JavaConversions._
object Allocator {
def main(args: Array[String]) {
val intargs = args.map(_.toInt)
println(allocate(intargs(0), intargs.slice(1, intargs.size).toVector))
}