Skip to content

Instantly share code, notes, and snippets.

View bearloga's full-sized avatar
🎲
RAND()

Mikhail Popov bearloga

🎲
RAND()
View GitHub Profile
@bearloga
bearloga / druid-csv-spec_country-all.json
Last active June 25, 2019 05:48
Druid ingestion spec for gzipped CSV data
{
"type": "index_hadoop",
"spec": {
"ioConfig": {
"type": "hadoop",
"inputSpec": {
"paths": "hdfs://analytics-hadoop/tmp/gsc-all.csv.gz",
"type": "static"
}
},
@bearloga
bearloga / dl2csv.R
Created November 9, 2017 18:15
Some code for converting an HTML description list into an R data.frame that can then be exported as a CSV.
library(rvest)
x <- "<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>"
y <- read_html(x)
@bearloga
bearloga / mkrproj.sh
Last active January 3, 2018 14:59
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
#!/bin/bash
# Usage: mkproj [projectname]
# projectname defaults to name of current directory
template="Version: 1.0\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 4\nEncoding: UTF-8\n\nRnwWeave: knitr\nLaTeX: pdfLaTeX"
wd=$(basename `pwd`)
if [ -z $1 ]; then
@bearloga
bearloga / wdqs-cocktails.R
Created April 21, 2017 18:48
Fetches cocktails and their ingredients from Wikidata using SPARQL and Wikidata Query Service
cocktails <- WikidataQueryServiceR::query_wikidata('
SELECT DISTINCT ?cocktailLabel ?ingredientLabel ?instanceOfLabel ?subclassLabel
WHERE
{
?cocktail wdt:P31/wdt:P279* wd:Q134768 .
?cocktail wdt:P186 ?ingredient .
OPTIONAL {
?ingredient wdt:P279 ?subclass .
}
OPTIONAL {
@bearloga
bearloga / app.R
Created January 24, 2017 02:07
A Shiny app with the header (title) panel fixed in place at the top as the user scrolls down.
header <- headerPanel("Hello Shiny!")
header[[2]]$attribs$id = "header"
ui <- fluidPage(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
),
header,
sidebarLayout(
sidebarPanel(sliderInput("obs", "Number of observations:", min = 0, max = 1000, value = 500)),
@bearloga
bearloga / test_2016-12-16_23:48:33.log.md
Last active December 20, 2016 17:10
Rscript test.R --start_date=2016-12-01 --end_date=2016-12-02 >> test_`date +%F_%T`.log.md 2>&1

Test Run

Parameters

start_date end_date omit_times disable_forecasts help
2016-12-01 2016-12-02 FALSE FALSE FALSE

Reports

Keybase proof

I hereby claim:

  • I am bearloga on github.
  • I am mikhailpopov (https://keybase.io/mikhailpopov) on keybase.
  • I have a public key ASCf0zmMPu2vZKS1L64MOIaEEZ2n4ZsLRhW64H1k0sO5TQo

To claim this, I am signing this object:

@bearloga
bearloga / upgrade_packages.R
Last active October 8, 2020 12:46
The script can be used to re-install packages after upgrading R (on Linux or Mac), since libraries cannot be reused between different minor versions (e.g. when upgrading 3.2.3 to 3.3.2). It detects when a package was installed from CRAN vs GitHub/Git and re-installs it using the appropriate func. Usage: `Rscript upgrade_packages.R`
# WMF only:
if (file.exists("/etc/wikimedia-cluster")) {
message('Detected that this script is being run on a WMF machine ("', Sys.info()["nodename"], '"). Setting proxies...')
Sys.setenv("http_proxy" = "http://webproxy.eqiad.wmnet:8080")
Sys.setenv("https_proxy" = "http://webproxy.eqiad.wmnet:8080")
}
# General use:
message("Checking for a personal library...")
if (!dir.exists(Sys.getenv("R_LIBS_USER"))) {
@bearloga
bearloga / clickable-imgs.js
Created September 28, 2016 19:22
Make the figures click-able in your RMarkdown=>HTML reports.
<script language="JavaScript">
$(function() {
/* Lets the user click on the images to view them in full resolution. */
$("div.figure img").wrap(function() {
var link = $('<a/>');
link.attr('href', $(this).attr('src'));
link.attr('title', $(this).attr('alt'));
link.attr('target', '_blank');
return link;
});
---
title: "dyEvent Example"
output:
html_document:
css: style.css
---
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(xts)
library(dygraphs)