Skip to content

Instantly share code, notes, and snippets.

@pkorpine
pkorpine / save_as_pdf_gs
Last active November 17, 2023 20:05
"Save as PDF" script for Google Docs
// Saves the current document in Google Docs as PDF to the same folder.
// Code from https://stackoverflow.com/questions/28312992/convert-google-doc-to-pdf-using-google-script-editior
// Just added onOpen() to add the script to the menubar.
function onOpen() {
var ui = DocumentApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('My scripts')
.addItem('Convert to PDF', 'convertPDF')
.addToUi();
@pkorpine
pkorpine / finnish_ansi_umlauts.json
Created December 8, 2020 15:16
Karabiner Finnish umlauts on ANSI keyboard using right option
{
"title": "Finnish umlauts on ANSI keyboard",
"rules": [
{
"description": "Right alt + ;' to öä (with or without shift)",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "semicolon",
@pkorpine
pkorpine / espoo_kalenteri.py
Last active March 1, 2020 21:35
Espoo Kalenteri
#!/usr/bin/env python3
# Retrieves Espoo calendar for the given unit and writes separate .ics files for each given group.
# 2020-03-01 Pekka Korpinen <pekka.korpinen@iki.fi>
import time
import argparse
import requests
import ics
def get_unit_data():
@pkorpine
pkorpine / memcpy_16to32.c
Last active October 8, 2018 08:24
memcpy 16-bit values to 32-bit values (zero extend using SSE4.1)
#include <smmintrin.h>
void memcpy_16to32(uint32_t *pdst_, const uint16_t *psrc_, size_t n)
{
size_t items = n / sizeof(uint16_t);
__m128i *psrc = (__m128i *) psrc_;
__m128i *pdst = (__m128i *) pdst_;
while (items >= 8) {
@pkorpine
pkorpine / petalinux-env-2016.1.Dockerfile
Created September 7, 2018 12:23
Dockerfile for PetaLinux 2016.1 environment. The actual binaries are given in a volume.
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y \
build-essential \
tofrodos \
iproute \
tftpd-hpa \
gawk \
gcc \
make \
@pkorpine
pkorpine / iperf3_loopback.sh
Created February 17, 2017 10:59
Create external loopback between two network interfaces
#!/bin/sh
# Scripted from http://serverfault.com/questions/127636/force-local-ip-traffic-to-an-external-interface
DEV_0="ens6f0"
DEV_1="ens6f1"
MAC_0=`ifconfig ${DEV_0}|awk 'NR==1 {print $5}'`
MAC_1=`ifconfig ${DEV_1}|awk 'NR==1 {print $5}'`
IP_0="192.168.100.1"
IP_1="192.168.101.1"
FAKE_0="192.168.102.1"
@pkorpine
pkorpine / fix_vivado_2016-4.sh
Created January 20, 2017 07:53
Fix Vivado 2016.4 on Ubuntu
sed -sEi.bak 's/\(awk/\(LD_LIBRARY_PATH= awk/g' /opt/Xilinx/{Vivado,SDK}/2016.4/bin/loader
@pkorpine
pkorpine / install_vivaldi.sh
Created January 17, 2017 07:37
Add Vivaldi repo to Debian/Ubuntu
echo "deb http://repo.vivaldi.com/stable/deb/ stable main" | sudo tee /etc/apt/sources.list.d/vivaldi.list > /dev/null
wget -O - http://repo.vivaldi.com/stable/linux_signing_key.pub | sudo apt-key add -
sudo apt update && sudo apt install vivaldi-stable
@pkorpine
pkorpine / radiorock.php
Created December 19, 2016 08:19
Redirect to Radio Rock's mp3 stream (which url keeps changing)
<?php
$url = 'http://www.radiorock.fi/api/content?tagCategory=info&page=0';
$data = file_get_contents($url);
preg_match('/http:\/\/icelive.*?mp3/', $data, $m);
$stream_url = $m[0];
header("Location: $stream_url");
exit();
@pkorpine
pkorpine / .bashrc
Created February 5, 2015 14:41
Git repo status to bash prompt
# Git prompt
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
GIT_PS1_SHOWDIRTYSTATE="yes"
PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w $(__git_ps1 "\[\033[01;35m\]%s\[\033[34m\]")\$\[\033[00m\] '