Skip to content

Instantly share code, notes, and snippets.

View muety's full-sized avatar
🤓

Ferdinand Mütsch muety

🤓
View GitHub Profile
@muety
muety / TwoSum.scala
Created March 27, 2019 08:45
LeetCode TwoSum Solution Scala
// https://leetcode.com/problems/two-sum
object TwoSum {
def apply(nums: Array[Int], target: Int): Array[Int] = {
nums.view.zipWithIndex.map(x => {
val el = nums.view.zipWithIndex.drop(x._2 + 1).collectFirst {
case y if y._1 + x._1 == target => y
}
Array(Option(x), el)
}).collectFirst {
import scala.io.Source
object Advent {
def main(args: Array[String]): Unit = {
val data = Source.fromFile("data/day1.txt").getLines.map(_.toInt).toList
println(f"Part 1: ${data.sum}")
/* Can someone help me get this second part a littler more Scala-like (more functional, less procedural)? Please let me know! */
var seen: Set[Int] = Set()
@muety
muety / vpn.md
Created November 17, 2018 06:32
Use FritzBox IPSec VPN on Ubuntu 18.04

FritzBox VPN on Ubuntu 18.04

  • Configure VPN for a user on your FritzBox and don't forget to show the pop-up including your credentials etc. afterwards. Also make sure you check "Allow access from internet".
  • sudo apt install vpnc network-manager-vpnc
  • Create file /etc/vpnc/vpn.conf, paste the following content and insert your credentials etc.
IPSec gateway yourfritzboxhere.myfritz.net
IPSec ID your_user
IPSec secret your_preshared_key

Keybase proof

I hereby claim:

  • I am muety on github.
  • I am n1try (https://keybase.io/n1try) on keybase.
  • I have a public key ASBHcQlgHHRLDR82SZGORIcw-TKTcUkburZy7YZAiE9DcQo

To claim this, I am signing this object:

@muety
muety / android_fullheight_gridview.java
Created May 22, 2018 14:03
A helper method that enables an Android GridView to be used inside a vertical ScrollView
/* Inspired by https://stackoverflow.com/a/27818661/3112139 */
public static void justifyListViewHeightBasedOnChildren (GridView listView) {
ListAdapter adapter = listView.getAdapter();
if (adapter == null) {
return;
}
ViewGroup vg = listView;
int totalHeight = 0;
for (int i = 0; i < adapter.getCount(); i++) {
@muety
muety / rclone_sync.txt
Last active December 20, 2022 20:32
Automated Google Drive sync for Linux using rclone
Script that will trigger a local to remote sync when any changes below your local Google Drive folder occur - but at max. every 10 minutes - and a remote to local sync every x (e.g. 30 minutes) via a cron job.
0. Install rclone and configure it for Google Drive
1. Create files listed below
2. Configure rclone_watch_local.sh to be run on startup (e.g. using a systemd service unit)
3. Add a cron job that runs rclone_remote2local.sh every x (e.g. 30) minutes
----------------------
rclone_local2remote.sh
----------------------
@muety
muety / deezer2json.js
Last active November 29, 2019 19:55
Export Deezer playlist to JSON
/*
1. Go to Deezer.com and open the playlist you want to export, e.g. https://www.deezer.com/en/profile/850026602/loved
2. Scroll down to the very bottom
3. Open your browser's dev tools (F12 on Linux an Windows) and go to the Console tab
4. Paste the following one-line command and hit enter
*/
JSON.stringify(Array.prototype.slice.call(document.getElementsByClassName('datagrid-row song')).map(r => Object.assign({}, {title: r.getElementsByClassName('title')[0].childNodes[0].textContent, artist: Array.prototype.slice.call(r.querySelectorAll('[itemprop="byArtist"]')).map(a => a.textContent).reduce((acc, a) => a + ', ' + acc, '').slice(0, -2)})), null, 2)
@muety
muety / apriori.py
Last active February 14, 2018 09:36
Naive implementation of the Apriori algorithm in Python
# Naive implementation of the Apriori algorithm in Python
# Example 2 from https://en.wikipedia.org/wiki/Apriori_algorithm
data = [
{1,2,3,4},
{1,2,4},
{1,2},
{2,3,4},
{2,3},
{3,4},
@muety
muety / tripadvisor_scraper.py
Last active July 27, 2019 00:22
A scraper for restaurant reviews from Tripadvisor
'''
A script to scrape restaurant reviews from tripadvisor.com or tripadvisor.de using Selenium.
Author: Ferdinand Mütsch <[email protected]>
License: MIT
Updated: January, 09 2018
Installation:
- Install `selenium` and `pandas` using pip
- Install PhantomJS or get Chrome- or Firefox webdriver binaries and add them to your PATH (see http://selenium-python.readthedocs.io/installation.html#drivers)
@muety
muety / wsgi.py
Last active November 8, 2017 09:01
Sample WSGI web server with Flask
# gunicorn --bind 0.0.0.0:8000 --workers 4 wsgi:app
# gunicorn --bind 0.0.0.0:8000 --workers 1 --threads 12 wsgi:app
import time
from flask import Flask
app = Flask(__name__)
# Requests from one client are not blocked by long-lasting requests from another client, as long as there are workers available
@app.route('/sleep')