Skip to content

Instantly share code, notes, and snippets.

@sguzman
sguzman / collatz-grammar-analysis.wls
Created April 12, 2021 16:57
Studying collatz using even/odd tokens as a grammar
$RecursionLimit = Infinity
collatz[1] = 1
collatz[n_Integer /; And[n > 1, OddQ[n]]] := collatz[n] = 3 n + 1
collatz[n_Integer /; And[n > 1, EvenQ[n]]] := collatz[n] = n/2
collatzseq[1] = {1}
collatzseq[n_Integer /; n > 1] :=
collatzseq[n] = {n, Splice@collatzseq@collatz@n}
@sguzman
sguzman / cache-sp500.wls
Created March 28, 2021 03:20
Precache sp500 closing prices for all stocks
With[{items = EntityList@EntityClass["Financial", "SP500"]},
finhash[str_] := finhash[str] = FinancialData[str, "Close", All];
Monitor[
Table[
finhash[items[[n]]]
, {n, 1, Length@items}
]
, ProgressIndicator[n, {1, Length@items}]
]
]
@sguzman
sguzman / corr-again.wls
Created March 28, 2021 01:13
Rank correlation of sp500 stocks and cache results of computations
Block[{},
items = EntityList[EntityClass["Financial", "SP500"]];
finhash[str_] := finhash[str] = FinancialData[str, "Close", All];
datePath[str_] := datePath[str] = finhash[str]["DatePath"];
shared[a_, b_] :=
shared[a, b] = Intersection[Map[First, a], Map[First, b]];
assoc[data_] :=
assoc[data] = Association@Map[First@# -> Last@# &, data];
filterFrom[as_, sh_] := filterFrom[as, sh] = Map[as, sh];
@sguzman
sguzman / correlate-sp500.wls
Created March 27, 2021 22:59
Rank correlation of sp500 stocks for this year
Block[{tmp},
items = EntityList@EntityClass["Financial", "SP500"];
begin = DateObject[{2021, 1, 1}, "Day", "Gregorian", -7.`];
end = DateObject[{2021, 3, 3}, "Day", "Gregorian", -7.`];
fin[str_, beg_, en_] :=
fin[str, beg, en] = FinancialData[str, "Close", {beg, en}];
corr[stra_, strb_, beg_, en_] :=
corr[stra, strb, beg, en] =
Correlation[fin[stra, beg, en], fin[strb, beg, en]];
@sguzman
sguzman / correlate.wls
Last active March 23, 2021 21:20
Correlate stuff
With[{e = ents, t = ts, n = nums, size = 20},
With[{items = nums[[;; 20]]},
With[{list = Subsets[n, {2}]},
Grid[
TakeSmallestBy[
ParallelTable[
With[{a = ents[[First@ii]], b = ents[[Last@ii]],
x = ts[[First@ii]], y = ts[[Last@ii]]}, {
a,
b,
@sguzman
sguzman / countries.wls
Created March 20, 2021 20:23
Study countries by region
diff[ts_] := Transpose[{
ts["Dates"][[;; -2]],
Differences@ts["Values"]
}];
merge[list_] := GatherBy[
Table[
Splice@
diff[l]
, {l, list}]
, First];
@sguzman
sguzman / merge-ts.wls
Created March 20, 2021 19:09
Merge timeseries data
With[{list = {}},
Table[
{First@First@g, Total@Map[Last, g]},
{g, GatherBy[
Table[
Splice@
Transpose[{
l["Dates"][[;; -2]],
Differences@
l["Values"]
@sguzman
sguzman / n-gram-rank.wls
Created March 8, 2021 02:25
rank n grams in mathematica
With[{nlimit = 4, text = chs},
Grid@
TakeLargestBy[
Table[
{First@j, Last@j, Length@First@j * Last@j,
N@((Length@First@j * Last@j)/Length@text)}, {j,
Join @@
Table[
Tally@
Partition[text, i, 1], {i, 1, nlimit, 1}
Step 1
===
Download forge mod server plugin
https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.12.2-14.23.5.2838/forge-1.12.2-14.23.5.2838-installer-win.exe
Step 2
===
Download rlcraft mod
https://www.curseforge.com/minecraft/modpacks/rlcraft/download/2935323
@sguzman
sguzman / topology.txt
Created November 26, 2020 00:29
Topology of upcoming microservice architecture
Topology
===
Databases
======
- Channel Serials
- Channel Metadata
- Channel Timeseries
Microservices