Skip to content

Instantly share code, notes, and snippets.

@safferli
safferli / szi-montage.zsh
Created September 18, 2023 14:25
rename szi images to make them easily imagemagick-able
#!/bin/zsh
# szi file[1] setup is:
#
# col_row.jpg
#
# for imagemagick we want:
#
# row_col.jpg
#
setInterval(function() {
if (Molpy.Redacted.location != 0) {
document.title = "! kitten !";
Molpy.Redacted.location=1;
var inputz = document.getElementsByTagName("input");
for(index = 0; index < inputz.length; index++){
if(inputz[index].value == "Show"){
var foundIt = String(inputz[index].onclick).includes("Redacted");
@safferli
safferli / werewolf20.adoc
Last active January 28, 2019 14:21
Werewolf nWoD 2.0 rules adjustment

Cool stuff in the new 2.0 rules

  • The pack is far more in focus, with Wolfblooded and other "pack members" (allies, contacts, etc) having a more important role.

  • Each of the five shapeshift forms now has a unique role to play, and unique advantages. Social skills are no longer penalised.

  • Primal Urge is more meaningful and ties in better with the Spirit/Werewolf side.

  • Gifts are very cool and it’s easier to pick the ones you like. They are tied to your Renown now as well, giving each character more flavour.

Houserules

@safferli
safferli / wonderly.R
Last active September 25, 2017 13:08
Clean messed up wide/long format
library(tibble)
library(dplyr)
library(tidyr)
# generate dataset
dta <- tibble::data_frame(
Land = c(rep("Bahamas", 4), "Bahrein"),
Year = c(rep(c(1999, 2000), 2), 1999),
indicator1 = c(5, 6, NA, NA, NA),
indicator2 = c(5, 8, NA, NA, NA),
@safferli
safferli / IPconvert.R
Last active December 23, 2021 20:20
Convert IP strings to integers and reverse using cpp/boost, and Rcpp
library(Rcpp)
library(inline)
Rcpp::sourceCpp("iputils.cpp")
# test convert an IPv4 string to integer
rinet_pton("10.0.0.0")
#[1] 167772160
rinet_pton(c("10.0.0.0", "192.168.0.1"))
# [1] 167772160 -1062731775
library(dplyr)
library(data.table)
library(xlsx)
# Define your workspace: "X:/xxx/"
wd <- "D:/gitlab/analytics/"
setwd(wd)
f.drop.players <- function(server.size = 1000, playtime = 90, dispersion = 0.7) {
@safferli
safferli / metacritic-api.r
Last active November 12, 2017 16:40
Query the (unofficial) Mashape metacritic game API in R
## Usage:
## 1) sign up to the Mashape API to get metacritic data: https://market.mashape.com/byroredux/metacritic-v2
## 2) save your Mashape API key in your .Renviron as Mashape.key
## 3) generate a character vector of games you want to query
## 4a) call f.generate.metacritic.data(game.vector) to generate a dataframe of the results
## 4b) alternatively, call f.call.metacritic.API(game) if you want to only call the API for one game (returns the API result, not a dataframe)
library(httr)
library(jsonlite)
library(dplyr)
@safferli
safferli / curl_proxy_test
Created July 30, 2015 08:44
curl::ie_proxy_info() test
> library("curl")
> curl::ie_proxy_info()
$AutoDetect
[1] TRUE
$AutoConfigUrl
NULL
$Proxy
NULL
@safferli
safferli / SQL rank index
Created July 16, 2015 13:03
Efficiently rank in SQL. Rank 1 indexes all values, Rank 2 indexes over users, Rank 3 indexes over heroes (inside user)
SELECT df.*, @curRank := @curRank + 1 AS rank,
@prev := @curr,
@curr := user_id,
@rank2 := IF(@prev = @curr, @rank2, @rank2+1) AS rank2,
@rank3 := IF(@prev = @curr, @rank3+1, 1) AS rank3
FROM (
SELECT user_id, itemType,
extractvalue(data, '//heroId') as hero_id, time
FROM fct_generate_hero
ORDER BY user_id, time
@safferli
safferli / negative join
Created July 16, 2015 08:55
remove all instances in first table that exist in second table
library(data.table)
library(dplyr)
a <- data.table(x = c("A", "B", "C", "D"),
y = c(1, 2, 3, 4),
z = c("good", "bad", "bad", "good")) %>%
setkey(x, y)
b <- data.table(x = c("B", "C"),
y = c(2, 3)) %>%
setkey(x, y)