Skip to content

Instantly share code, notes, and snippets.

View Baekalfen's full-sized avatar

Mads Ynddal Baekalfen

  • Denmark
View GitHub Profile
@Baekalfen
Baekalfen / Run Async Method and run method afterwards
Created April 25, 2014 17:16
Running a method async, and call method on finish in Objective-C. Good for running method while updating the UI on OS X. Used some code from here: http://stackoverflow.com/questions/8854100/objective-c-async-call-a-method-using-ios-4
- (void) someMethod{
[self dispatchBlockAsync:^{
[self method1];
} callOnReturn:^{
[self method2];]
}];
}
- (void)dispatchBlockAsync:(void(^)(void))callBlock callOnReturn:(void(^)(void))returnBlock{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
@Baekalfen
Baekalfen / gist:7b1b9a0d0b9c4ce7d751
Last active August 29, 2015 14:07 — forked from Wysie/gist:7487571
Script to route traffic from home network through VPN selectively. Based off the discussion at http://www.smallnetbuilder.com/forums/showthread.php?t=9311 The setup is a Macbook, Apple Tv and a Raspberry Pi. The aim is to have all traffic from those 3 go through the VPN, all traffic from all other devices should bypassing the VPN.
#!/bin/sh
# Original script: https://gist.github.com/Wysie/7487571
#
# Script to route traffic from home network through VPN selectively.
# Based off the discussion at http://www.smallnetbuilder.com/forums/showthread.php?t=9311
# The setup is a Macbook, Apple Tv and a Raspberry Pi.
# The aim is to have all traffic from those 3 go through the VPN, all traffic from all other devices should bypassing the VPN.
#
# Requirements: Asuswrt-Merlin with OpenVPN already set up
@Baekalfen
Baekalfen / ParallelBatch.py
Created July 15, 2015 11:08
Run parallel tasks in Python
# ParallelBatch.py
#
# Created by Mads Ynddal on 15/07/15.
# 2015 Printix.net
#
from multiprocessing.pool import ThreadPool
class batch:
processes = 4
@Baekalfen
Baekalfen / Configuration.h
Created February 26, 2016 10:53
Marlin configuration
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
// This configurtion file contains the basic settings.
// Advanced settings can be found in Configuration_adv.h
// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration
//User specified version info of this build to display in [Pronterface, etc] terminal window during startup.
//Implementation of an idea by Prof Braino to inform user that any changes made
//to this build by the user have been successfully uploaded into firmware.
@Baekalfen
Baekalfen / gist:487b07570502332182091bc8c5d9235c
Created April 9, 2016 16:10
iTerm 2 beta 3.0 find exact line and column of error in Rust and go to error in Vim
iTerm:
Trigger regex: ^([a-zA-Z0-9+/.-]+):([0-9]+):([0-9]+): ([0-9]+):[0-9]+ (?:error):
Trigger action: Capture Output
Trigger parameter: echo ":call GetTabOrOpenFile(\"\1\")"; echo "$[\2 - 1]G\3|"
For .vimrc:
set swb=usetab
function! GetTabOrOpenFile(file)
try
execute "tab sb ".a:file
@Baekalfen
Baekalfen / ThreadPoolTemplate.cs
Last active May 3, 2016 09:33
C# .NET/Mono -- Quick template for using a ThreadPool
private struct Context
{
public string val;
public ManualResetEvent doneEvent;
}
private void FunctionOnContext(object context){
Context c = (Context)context;
lock (resultList) {
@Baekalfen
Baekalfen / pdf.sh
Last active January 3, 2017 09:28
My perfect Latex-to-PDF script. Clean output and also compiles bibtex references.
#!/bin/bash
# TEXNAME='${echo $1 | egrep -o "^([^.]*)"}'
TEXNAME=$(echo $1 | egrep -wo "^([^.]*)") # Strip up to first extension
echo $TEXNAME
cd $(dirname "$TEXNAME")
PATH=/usr/local/texlive/2014/bin/x86_64-darwin:$PATH
pdflatex -interaction=batchmode "$TEXNAME.tex"
echo ""
@Baekalfen
Baekalfen / find_devices.py
Created January 3, 2017 09:27
Small script to show a list of active WiFi devices on Asus routers
import subprocess
import sys
import time
des = sys.argv[1]
def call(cmd):
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# wait for the process to terminate
@Baekalfen
Baekalfen / mailalive.py
Created February 1, 2018 15:05
Check if two mail servers are alive
#!/usr/bin/python
import smtplib
import imaplib
import time
import random
import string
def send_mail(smtp_server, SSL, username, password, receiver, subject, body):
to = [receiver]