Skip to content

Instantly share code, notes, and snippets.

safferli

Block or report user

Report or block safferli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@safferli
safferli / werewolf20.adoc
Last active Jan 28, 2019
Werewolf nWoD 2.0 rules adjustment
View werewolf20.adoc

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 Sep 25, 2017
Clean messed up wide/long format
View wonderly.R
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 May 10, 2016
Convert IP strings to integers and reverse using cpp/boost, and Rcpp
View IPconvert.R
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
View apply()-woes.r
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 Nov 12, 2017
Query the (unofficial) Mashape metacritic game API in R
View metacritic-api.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 Jul 30, 2015
curl::ie_proxy_info() test
View curl_proxy_test
> library("curl")
> curl::ie_proxy_info()
$AutoDetect
[1] TRUE
$AutoConfigUrl
NULL
$Proxy
NULL
@safferli
safferli / SQL rank index
Created Jul 16, 2015
Efficiently rank in SQL. Rank 1 indexes all values, Rank 2 indexes over users, Rank 3 indexes over heroes (inside user)
View SQL rank index
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 Jul 16, 2015
remove all instances in first table that exist in second table
View negative join
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)
@safferli
safferli / lseq.r
Last active Dec 2, 2015
Create a logarithmic sequence to properly set logticks in ggplot()
View lseq.r
lseq <- function(from=1, to=100000, length.out=6) {
# logarithmic spaced sequence
# blatantly stolen from library("emdbook"), because need only this
exp(seq(log(from), log(to), length.out = length.out))
}
You can’t perform that action at this time.