Skip to content

Instantly share code, notes, and snippets.

View peterdalle's full-sized avatar

Peter M. Dahlgren peterdalle

View GitHub Profile
@peterdalle
peterdalle / download.sh
Created March 24, 2016 14:29
Automatically download files via SSH without password
#!/usr/bin/bash
# Download CSV files from Linux server (iny my case, Raspberry Pi and Ubuntu)
# over SSH without the need to supply password. Note that Cygwin have to be
# used with this file since Git Bash uses other keyfiles.
#
# 1.Upload keyfiles:
# scp /home/username/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys2
# 2. Don't forget to make file executable:
# chmod +x download.sh
@peterdalle
peterdalle / convertdocx2text.bat
Created May 10, 2016 08:05
Batch file to convert all DOCX files in the current directory to TXT files using Pandoc.
@echo off
REM Batch file to convert all DOCX files in the current directory to TXT files using Pandoc.
for %%f in (*.docx) do (
echo %%~nf
pandoc -f docx -t plain -o "%%~nf.txt" "%%~nf.docx"
)
@peterdalle
peterdalle / medieormen.r
Created June 15, 2016 11:13
Show total article shares, comments and per month by Aftonbladet from 2014-06-01 to 2016-03-01.
# Hämta artikeldelningar per dag av Aftonbladets artiklar från 2014-06-01 till 2016-03-01.
df.ab <- GetSharesDf("SELECT '' title, DATE(pubdate) pubdate, SUM(fblikes) fblikes, SUM(fbshares) fbshares, SUM(fbcomments) fbcomments, SUM(twitter) twitter FROM articles WHERE sourcegroupid=1 AND DATE(pubdate) BETWEEN '2014-06-01' AND '2016-03-01' GROUP BY DATE(pubdate) ORDER BY retrieved ASC")
# Plotta ett mått i taget.
plotvar <- function(df, measure, title)
{
df.m <- melt(df, id.vars = "pubdate", variable.name = measure)
gg <- ggplot(data=df.m, aes(as.Date(pubdate), value)) +
geom_line(size=1, color="#3b5998", alpha=0.6) +
scale_y_continuous(labels=scales::comma) + # Y-axel brytpunkter
@peterdalle
peterdalle / reverse-score.r
Created August 7, 2016 10:05
Reverse scale score
reverse.score = min.score + max.score - actual.score
# For example, a 7-point Likert scale where 1=good and 7=bad can be reversed scored as follows:
# 1 + 7 - 1 = 7
# 1 + 7 - 2 = 6
# 1 + 7 - 3 = 5
# 1 + 7 - 4 = 4
# 1 + 7 - 5 = 3
# 1 + 7 - 6 = 2
@peterdalle
peterdalle / swedish-stopwords.txt
Last active October 8, 2021 10:46
Svenska stoppord (Swedish stop words) - se https://github.com/peterdalle/svensktext för uppdaterad version
aderton
adertonde
adjö
aldrig
all
alla
allas
allt
alltid
alltså
@peterdalle
peterdalle / statistics-distributions.js
Created August 22, 2016 16:28
JavaScript library for calculating critical values and upper probabilities of common statistical distributions
/*
* NAME
*
* statistics-distributions.js - JavaScript library for calculating
* critical values and upper probabilities of common statistical
* distributions
*
* SYNOPSIS
*
*
@peterdalle
peterdalle / DeleteOldCalendarEvents.gs
Last active September 13, 2016 20:16
Delete old calendar events from Google Calendar
// Adapted from http://webapps.stackexchange.com/questions/19513/how-to-delete-all-events-on-many-dates-all-at-once-but-not-the-whole-calendar-in/47768#47768
var fromDate = new Date(2016, 01, 1, 0, 0, 0);
var toDate = new Date(2016, 12, 31, 0, 0, 0);
removeEvents(fromDate, toDate, "MyFirstCalendar");
removeEvents(fromDate, toDate, "MySecondCalendar");
function removeEvents(fromDate, toDate, calendarName) {
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
@peterdalle
peterdalle / DeleteAllTwitterDirectMessages.py
Created September 13, 2016 20:21
Delete all Twitter direct messages
#!/usr/bin/python2
# Credit: https://gist.github.com/nileshgr/3388917
# Go to dev.twitter.com/apps and create a new app; put the information here.
# You need the tweepy library.
consumer_secret = ''
consumer_key = ''
access_token_key = ''
@peterdalle
peterdalle / retrodesign.r
Created October 25, 2016 16:03
Calculate Type S (sign) and Type M (magnitude) errors
# Source:
# Gelman, A., & Carlin, J. (2014). Beyond Power Calculations: Assessing Type S (Sign) and Type M (Magnitude) Errors. Perspectives on Psychological Science, 9(6), 641–651.
# https://doi.org/10.1177/1745691614551642
#
# From p. 643:
# We have implemented these calculations in an R function, retrodesign().
# The inputs to the function are D (the hypothesized true effect size),
# s (the standard error of the estimate), D (the statistical significance
# threshold; e.g., .05), and df (the degrees of freedom). The function
# returns three outputs: the power, the Type S error rate, and the
@peterdalle
peterdalle / robots.txt
Created December 3, 2016 15:18
Robots.txt that makes sure Facebook and Twitter can crawl images on your site.
# Disallow everything.
User-agent: *
Disallow: /
# Certain social media sites are whitelisted to allow crawlers to access page markup when links to /images are shared.
User-agent: Twitterbot
Allow: /images
User-agent: facebookexternalhit
Allow: /images