Skip to content

Instantly share code, notes, and snippets.

View robertzk's full-sized avatar

Robert Krzyzanowski robertzk

View GitHub Profile
@robertzk
robertzk / keybase.md
Created July 31, 2024 06:41
keybase.md

Keybase proof

I hereby claim:

  • I am robertzk on github.
  • I am robertzk (https://keybase.io/robertzk) on keybase.
  • I have a public key ASCNP0cMjdCV7EiZAWBarlaEX29aegpkkPCeFvspkM0ELwo

To claim this, I am signing this object:

@robertzk
robertzk / lunchnlearn-073017.md
Last active July 31, 2017 20:02
Lunch & Learn 07/30/17: R environments
env <- new.env()

d <- 1
fn <- function(a, b) {
  a + b + d
}

fn2 <- (function() {
  d <- 2
@robertzk
robertzk / r-python.md
Last active April 7, 2016 16:20
R-Python itertools rosetta stone

A translation of Python's itertools to R.

count(10) # 10 11 12 13 14 ...
count <- function(x, step = 1) {
  function() { (x <<- x + step) }
}
@robertzk
robertzk / capture_stack_trace.R
Created January 19, 2016 23:30
Capture an R stack trace
capture_calls <- function(e) {
e$calls <- sys.calls()
signalCondition(e)
}
fn <- function(x) {
call_another_function(x + 1)
}
call_another_function <- function(y) {
@robertzk
robertzk / example_fn_aliasing.R
Created January 16, 2016 00:36
Example of function aliasing
for (i in 1:10) {
assign(paste0("fn", i), eval(bquote(function(x) { x + .(i) })))
}
#' This is my function.
#'
#' This does stuff.
#'
#' @param x
#' @return foo.
@robertzk
robertzk / error_handling.R
Created November 2, 2015 23:11
Capture error handling in R
ref_filename <- function(ref) {
attr(ref, "srcfile")$filename
}
frame_text <- function(frame) {
if (identical(frame, .GlobalEnv)) {
structure(pkg = "_global",
"global environment"
)
@robertzk
robertzk / s3subset.R
Created September 2, 2015 22:31
S3 subsetting overloading
wrapped <- function(obj) {
structure(obj, class = "wrapped")
}
`[[.wrapped` <- function(obj, x) {
if (x == "predict") {
.subset2(obj, x)
} else {
.subset2(obj, "model")[[x]]
}
@robertzk
robertzk / Github-PAT-Help.md
Last active September 28, 2017 21:36
Help with setting up Github PAT token

Ensure you have a Github account. Next, visit the Github help page to set up your Github auth token.

Make sure git is installed. Open up your terminal, and ensure git is installed by running which git (if you do not see git not found, then you have to do nothing). If you do not have git, run brew install git. Next, configure your git identity.

Finally, copy the authenatication token you obtained earlier, and then run the following line from your terminal (with the token replaced by your token):

echo "export GITHUB_PAT=c1e2feed3242cfa0ab2e560ce4f380f66c6e9547" >> ~/.bash_profile && source ~/.bash_profile
@robertzk
robertzk / Setting-Up-Hipchat-Token.md
Last active August 29, 2015 14:27
Setting up your hipchat token.

Setting up your Hipchat API token

First, visit the Hipchat account API page. You will have to login with you avantcredit.com hipchat account.

Scroll down and create your Hipchat token with the following permissions:

Create New Token

The token should appear in the list above. Copy the token, and then run the following line from your terminal (with the token replaced by your token):

@robertzk
robertzk / send.vim
Created July 26, 2015 14:12
vim send macro
let @s='^i! git add "$(git rev-parse --show-toplevel)"; git commit -m "^[$a"; git push -q origin `git rev-parse --abbrev-ref HEAD` &^[dd;w^M;@"^M^M^['