Skip to content

Instantly share code, notes, and snippets.

require 'open-uri'
require 'CSV'
require 'mysql2'
require 'json'
start = [1,1,1992]
name_list = "../data/sp"
file = File.new(name_list+"_selected.csv", "r")
start_from = "" # if download hangs or crashes, start from stock with this symbol
@jjkrol
jjkrol / ampl.run
Created October 25, 2013 08:31
[AMPL] loop
reset;
model MODEL_FILE.mod;
data DATA_FILE.dat;
let VARIABLE := INITIAL_VALUE;
display VARIABLE > OUTPUT_FILE.txt;
for {1..15}{
solve;
display GOAL_VARIABLE >> OUTPUT_FILE.txt;
let VARIABLE := VARIABLE+1;
}
@jjkrol
jjkrol / gist:6570815
Last active December 23, 2015 02:59
[R] Generate k random permutations of a given vector
#' Create k random permutations of a vector
#' should be used only for length(input)! >> k
#' @param input vector to be permutated
#' @param k number of permutations
gen.samp <- function(input,k){
n <- length(input)
mat <- matrix(data=NA,nrow=k,ncol=n) # allocate memory
k <- min(k, nperm(input))
inserted <- 0
while(inserted < k){
@jjkrol
jjkrol / gist:6540577
Created September 12, 2013 16:44
[HTML] angular + bootstrap template
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
@jjkrol
jjkrol / gist:5894869
Created June 30, 2013 11:44
[R] Plot addresses on a map
# Input data:
# a data frame with columns from and to (each containing addresses readable for Google Maps)
# if you already have a vector of addresses, omit the all.addresses <- ... line
library(ggmap)
AddressFrequency <- function(addresses){
tab <- table(addresses)
unique.points <- data.frame(address=names(tab), frequency = c(tab))
rownames(unique.points) <- NULL
unique.points
@jjkrol
jjkrol / gist:5891966
Last active December 19, 2015 03:39
[R] Calculate distances
library(ggmap) # mapdist
library(xlsx) # read.xlsx
# Data for these functions was stored in an xlsx file:
# date | from | city from | to | city to | who | back | comment |
# usage:
# df <- read.xlsx("routes.xlsx", 1, encoding="UTF-8", stringsAsFactors=F)[,1:7]
# df <- PasteCities(df)
# kilometers <- GetDistancesImproved(df)
@jjkrol
jjkrol / import_data.rb
Created February 11, 2013 12:06
[Ruby] import stock data
require 'open-uri'
require 'CSV'
require 'mysql2'
require 'json'
start = [1,1,1992]
name_list = "small_cap"
file = File.new(name_list+"_selected.csv", "r")
start_from = "" # if download hangs or crashes, start from stock with this symbol
@jjkrol
jjkrol / find_fitting_stocks.rb
Created February 11, 2013 12:04
[Ruby] find fitting stocks
# find stocks, that fit certain requirements, considering long period of records and no big gaps
# place list with stock to filter in the file [name_list]_full.csv
# results will be stored in [name_file]_selected.csv
require 'open-uri'
require 'CSV'
start = Date.new(1992,1,1)
max_gap = 7
name_list = "mid_cap"
@jjkrol
jjkrol / gist:4258646
Created December 11, 2012 13:41
Gradient matlab
function wynik = gradient_in_point(point)
x = point(1)-4:0.1:point(1)+4;
y = point(2)-4:0.1:point(2)+4;
[x y] = meshgrid(x,y);
z = (1.5 - x .* (1- y )).^2 + (2.25 - x .*(1- y.^2)).^2 + (2.625 - x .* (1- y.^3)).^2;
[px py] = gradient(z);
middle = (4+4)/0.1/2;
wynik = [-1*px(middle,middle) -1*py(middle,middle)];
end
@jjkrol
jjkrol / gist:4013546
Created November 4, 2012 20:22
Popty - sprawozdanie
\documentclass[10pt,a4paper]{article}
\usepackage{fullpage}
\usepackage{graphicx} %grafiki
\usepackage{color}
\usepackage{amsmath} % matematyka
\usepackage{mathtools} % matematyka
\usepackage{amssymb} % symbole, np. triangleeq
\usepackage{float}
\usepackage[OT4]{polski}
\usepackage[utf8x]{inputenc}