Skip to content

Instantly share code, notes, and snippets.

Avatar

Mads Ynddal Baekalfen

  • Denmark
View GitHub Profile
@Baekalfen
Baekalfen / mailalive.py
Created Feb 1, 2018
Check if two mail servers are alive
View mailalive.py
#!/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]
@Baekalfen
Baekalfen / find_devices.py
Created Jan 3, 2017
Small script to show a list of active WiFi devices on Asus routers
View find_devices.py
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 / pdf.sh
Last active Jan 3, 2017
My perfect Latex-to-PDF script. Clean output and also compiles bibtex references.
View pdf.sh
#!/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 / ThreadPoolTemplate.cs
Last active May 3, 2016
C# .NET/Mono -- Quick template for using a ThreadPool
View ThreadPoolTemplate.cs
private struct Context
{
public string val;
public ManualResetEvent doneEvent;
}
private void FunctionOnContext(object context){
Context c = (Context)context;
lock (resultList) {
@Baekalfen
Baekalfen / gist:487b07570502332182091bc8c5d9235c
Created Apr 9, 2016
iTerm 2 beta 3.0 find exact line and column of error in Rust and go to error in Vim
View gist:487b07570502332182091bc8c5d9235c
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 / Configuration.h
Created Feb 26, 2016
Marlin configuration
View Configuration.h
#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 / ParallelBatch.py
Created Jul 15, 2015
Run parallel tasks in Python
View ParallelBatch.py
# ParallelBatch.py
#
# Created by Mads Ynddal on 15/07/15.
# 2015 Printix.net
#
from multiprocessing.pool import ThreadPool
class batch:
processes = 4
@Baekalfen
Baekalfen / gist:7b1b9a0d0b9c4ce7d751
Last active Aug 29, 2015 — 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.
View gist:7b1b9a0d0b9c4ce7d751
#!/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 / Run Async Method and run method afterwards
Created Apr 25, 2014
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
View Run Async Method and run method afterwards
- (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);
You can’t perform that action at this time.