Skip to content

Instantly share code, notes, and snippets.

@TobCap
TobCap / FlattenDictionary.swift
Created October 11, 2017 08:04
flatten dictionary, ignore deeper level of nested dictionary by `keepLevel`
func flattenDictionary(dic: [String: Any], keepLevel: UInt = UInt.max) -> [String: Any] {
var result: [String: Any] = [:]
func flattenDic(_ dic: [String: Any], out: inout [String: Any], level: UInt, addedKey: String = "") {
if level == 0 { return }
for (key, val) in dic {
let modKey = addedKey + key
if let val = val as? [String: Any] {
flattenDic(val, out: &out, level: level - 1, addedKey: modKey)
} else {
@TobCap
TobCap / gist:5cce10e98840ee651829b21a68efdc13
Last active December 4, 2021 07:36
R lang tail recursion optimization

R language tail (call|recursion) (optimization|elimination)

List of packages or documents

URL type author (twitter) depends on note
trampoline package @ecologician coro, fastmap, rlang
rcompilertools (tweet post) package @dirk_sch compiler, utils, tibble byte compiler
tailr

調査目的

Windows 10 laptop の価格を比較

調査時点

2020/05/24

背景

Windows 10 WSL2 で NDIVIA GeForce を動かしたい。RAM 32GB 限定

条件

# install.packags(c("xml2", "stringr", "dplyr"))
library(xml2)
library(stringr)
library(dplyr)
code <- 7267
url_ <- paste0("http://resource.ufocatch.com/atom/edinet/query/", code)
x <- read_xml(url_)
# Original is https://gist.github.com/msakai/e39c25930b661e8175759cc15175d952
# Forked at 2020-01-09
# Attempt to mimick following GADT (Generalized algebraic data type) in Python:
#
# data Expr a where
# Const :: a -> Expr a
# Add :: Expr Int -> Expr Int -> Expr Int
# Eq :: Expr Int -> Expr Int -> Expr Bool
# IfThenElse :: Expr Bool -> Expr a -> Expr a -> Expr a
@TobCap
TobCap / async-example.py
Created August 27, 2019 14:32
python async await example
import asyncio
from time import time
async def slow_a():
print("a start")
await asyncio.sleep(2.5)
print("a end")
async def slow_b():
print("b start")
@TobCap
TobCap / repeat_dataframe.r
Created August 21, 2018 06:24
repeat_dataframe
library(tidyverse)
A <- data.frame(x = 1:3, y = letters[1:3], stringsAsFactors = FALSE)
shape <- matrix(1, 2, 3)
rep_df <- function(df_, shape) {
df_ %>%
list() %>%
matrix %>%
kronecker(shape, FUN = rep.int) %>%
@TobCap
TobCap / 20180620
Created June 20, 2018 04:02
too long sentences for rechord.cc
# Copyright(c) 2018 @tobakucptlsm
# Released under the MIT license
# http://opensource.org/licenses/mit-license.php
Gm911|Em911|Fm79/Bb|=|
Gm911|Em911|EbM7913|=|
Gm911======Em911|=|
Fm7911|====_Gbm7911_Gm911|
=======Em911|=======EbM7913|
=|=|
Sys.setenv(LANG="C") # for english error message on Windows
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.4.4
#> Warning: package 'tibble' was built under R version 3.4.4
#> Warning: package 'tidyr' was built under R version 3.4.4

#sessionInfo()
#with(R.version, print(c(platform, version.string)))