Skip to content

Instantly share code, notes, and snippets.

View alesk's full-sized avatar

Aleš Kotnik alesk

View GitHub Profile
@alesk
alesk / README.md
Created December 3, 2021 10:18
Python evaluation

When func_with_dict_1 is loaded, dict literal ret in it is not constructed. Dict ret is constructed on call and get_value with side effect is called.

Example running python3 lazy_consumer.py:

Before calling func_with_dict_1
Called from txt
After calling func_with_dict_1
@alesk
alesk / month_hall.R
Last active November 30, 2018 10:05
Simulation of Monty Hall problem
library(tidyverse)
# number of simulations
N = 10000
# possible doors
doors <- c('A', 'B', 'C')
# choose a dor where there is no car and user didn't choose it
showed <- function(car, choice) {
@alesk
alesk / REDME.md
Created October 18, 2018 13:10
Running crond in dockerised alpine linux under non-root user

Create a script cron.sh that reports current user and environment

#!/bin/sh
env

and crontab that runs script from user's folder.

@alesk
alesk / keybase.md
Created October 1, 2018 06:12
keybase.md

Keybase proof

I hereby claim:

  • I am alesk on github.
  • I am alesk (https://keybase.io/alesk) on keybase.
  • I have a public key ASAMVR8C4F9EPnIObpkptx67uQ-HMDO4OsrxBGtw092Fjwo

To claim this, I am signing this object:

@alesk
alesk / gist:e2854e65b48d2b6fafd58af1530776fa
Last active March 4, 2018 07:18
Merge structs to flat map with string keys
/* Inspired by Stephen Weinberg's code:
https://play.golang.org/p/_r-bQIw347
https://stackoverflow.com/questions/12994679/golang-slice-of-struct-slice-of-interface-it-implements
Playground link: https://play.golang.org/p/czGSeErfndO
*/
package main
import (
@alesk
alesk / bind.rb
Created February 2, 2018 16:20
Using module instance methods to call in context of another object
module Rules
def rule_a
puts "#{a} #{b}"
end
def rule_b
puts "Total #{a+b}"
end
end
@alesk
alesk / aws-test.rb
Created January 29, 2018 14:48
Uploading strings to s3 in ruby
# vim: tabstop=2 expandtab shiftwidth=2
# upload csv file to s3
#
require 'aws-sdk-s3'
require 'csv'
require 'prawn'
OPTIONS = {region: 'eu-west-1',
access_key_id: 'ACCESS_KEHY_ID',
@alesk
alesk / normal-family.R
Created September 27, 2017 21:26
Produces animation of an arbitrary normal distribution getting closer to standard normal
library(tidyverse)
library(ggplot2)
library(gganimate)
library(animation)
plot_normal <- function(mean, sd) {
data_frame(x=seq(-10,10,by=0.05)) %>%
ggplot() +
scale_y_continuous(limits=c(0,1)) +
scale_x_continuous(limits=c(-7,7)) +
@alesk
alesk / crosses_and_checks.R
Created September 7, 2017 09:12
Display R dataframe with croses and checks in places of FALSE and TRUE
# Checkmarx and crosses in markdown table
library(knitr)
library(magrittr)
bools <- function() sample(c(T, F), 10, replace=T)
df <- data.frame(
one=bools(),
two=bools(),
@alesk
alesk / floor_monday.md
Last active August 18, 2017 10:25
Floor monday

Truncate date to the last Monday

R

library(lubridate)
floor_monday <- function(dat) { floor_date(dat - days(1), "week") + days(1) }

Python