Skip to content

Instantly share code, notes, and snippets.

View kvasilopoulos's full-sized avatar
:octocat:
Focusing

Kostas Vasilopoulos kvasilopoulos

:octocat:
Focusing
View GitHub Profile
@kvasilopoulos
kvasilopoulos / git-ssh-auth-win-setup.md
Created July 25, 2021 23:01 — forked from bsara/git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows

Setup SSH Authentication for Git Bash on Windows

Prepararation

  1. Create a folder at the root of your user home folder (Example: C:/Users/uname/) called .ssh.
  2. Create the following files if they do not already exist (paths begin from the root of your user home folder):
  • .ssh/config
@kvasilopoulos
kvasilopoulos / return-two-values.R
Created August 8, 2020 01:01
How to assign from a function which returns more than one value?
# (https://stackoverflow.com/questions/1826519/how-to-assign-from-a-function-which-returns-more-than-one-value)
':=' <- function(lhs, rhs) {
frame <- parent.frame()
lhs <- as.list(substitute(lhs))
if (length(lhs) > 1)
lhs <- lhs[-1]
if (length(lhs) == 1) {
do.call(`=`, list(lhs[[1]], rhs), envir=frame)
return(invisible(NULL))
}
@kvasilopoulos
kvasilopoulos / cran-policy.txt
Created April 23, 2020 17:15
Packages which use Internet resources should fail gracefully
CRAN policy:
''Packages which use Internet resources should fail gracefully with an
informative message if the resource is not available (and not give a
check warning nor error).'
@kvasilopoulos
kvasilopoulos / restore-delete-file-git
Created December 11, 2019 22:10
Find and restore a deleted file in a Git repository
Copied from https://stackoverflow.com/questions/953481/find-and-restore-a-deleted-file-in-a-git-repository
Find the last commit that affected the given path. As the file isn't in the HEAD commit, this commit must have deleted it.
git rev-list -n 1 HEAD -- <file_path>
Then checkout the version at the commit before, using the caret (`^`) symbol:
git checkout <deleting_commit>^ -- <file_path>
@kvasilopoulos
kvasilopoulos / land-registry-sparql.php
Created September 12, 2019 21:07 — forked from hubgit/land-registry-sparql.php
Fetch Land Registry transaction data using SPARQL
<?php
$curl = curl_init('http://landregistry.data.gov.uk/landregistry/query');
curl_setopt_array($curl, array(
CURLOPT_VERBOSE => true,
CURLOPT_ENCODING => 'gzip,deflate',
CURLOPT_HTTPHEADER => array('Accept: text/plain'),
));
@kvasilopoulos
kvasilopoulos / git+overleaf+github.md
Created August 19, 2019 18:12 — forked from jnaecker/git+overleaf+github.md
Using Overleaf as your TeX editor but getting your files to Github

git + overleaf + github

Setup

Connect Overleaf and your local repo

  1. Make a new project on Overleaf.
  2. In the share menu, copy the link from "Clone with git"
  3. On your computer:
    • use cd to navigate to where you want to put your project

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@kvasilopoulos
kvasilopoulos / cmd.sh
Last active August 21, 2019 11:54
Git tag after CRAN version acceptance
<!-- If you’re not using GitHub or you want to create a tag without a release on GitHub.
You can use the follow git commands: -->
git tag -a v1.0.0 -m "Releasing version v1.0.0"
git push --tags
@kvasilopoulos
kvasilopoulos / historical_sp500.R
Last active August 12, 2019 16:48
Download Historical S&P500 Price and Dividends from Shiller's dataset. The output is a formatted data.frame.
pkgs <- c("readxl", "lubridate", "zoo", "dplyr")
lapply(pkgs, require, character.only = TRUE)
temp <- paste0(tempfile(), ".xls")
file <- download.file("http://www.econ.yale.edu/~shiller/data/ie_data.xls",
destfile = temp, mode = "wb")
sp500 <- read_excel(path = temp,
sheet = "Data",
col_types = c("text", "skip", "skip", "skip",
@kvasilopoulos
kvasilopoulos / progressbar_doParallel_foreach.R
Last active April 10, 2024 08:27
How to include progressbar with doParallel (previously done only with the doSNOW-package) and foreach loop. Note, that you can easily wrap this into a function.
library(doParallel)
# Choose number of iterations
n <- 100
# Progress combine function
f <- function(iterator){
pb <- txtProgressBar(min = 1, max = iterator - 1, style = 3)
count <- 0
function(...) {