Skip to content

Instantly share code, notes, and snippets.

@eaydin
eaydin / screen_switch.sh
Last active August 11, 2020 07:34
Autoscreen Switch with Dock
#!/bin/bash
#######
# A **very** dirty hack to switch second and third screen.
# The reasons behind this is that, my Thinkpad dock always assigns random device names
# whenever I connect the Thinkpad to it. Therefore I cannot save the setting and call it back.
# This script has some assumptions:
# * Alternative screen names always start with 'DP-'
# * The laptop's screen name is always 'eDP-1'
# * The laptop is the left-most screen.
@eaydin
eaydin / NC-MySQLDUMP.sh
Created November 13, 2017 13:03 — forked from vanjos/NC-MySQLDUMP.sh
Easy way to do a mysqldump and restore using netcat (this is NOT encrypted)
#####
# You'll be needing two machines, the target machine and source one (makes sense, right)?
#####
# On the target machine
nc -l 55555 | gzip -d -c | mysql <database name> -u<user> -p<password> [ | <decrypt> ]
#####
# On the source machine
mysqldump -u<user> -p<password> <database name> | gzip | nc <ip of target server> 55555 [ | <encrypt> ]
@eaydin
eaydin / udp_hole_punch_tester.py
Created October 31, 2017 11:49 — forked from somic/udp_hole_punch_tester.py
UDP Hole Punching test tool
#!/usr/bin/env python
#
# udp_hole_punch_tester.py - UDP Hole Punching test tool
#
# Usage: udp_hole_punch_tester.py remote_host remote_port
#
# Run this script simultaneously on 2 hosts to test if they can punch
# a UDP hole to each other.
#
# * remote_port should be identical on 2 hosts.
def parity_check(incoming, type="even"):
"""Pass the incoming bits as string"""
if type != "even" and type != "odd":
return -1
if type == "even":
sum = 0
if type == "odd":
sum = 1
for i in incoming: sum += int(i)
return sum % 2
@eaydin
eaydin / crc8dallas.py
Last active August 15, 2024 15:35
CRC8 Maxim/Dallas for Python
############################################
# This is for CRC-8 Maxim/Dallas Algorithm
# Improved with less variable and functions
# Supports both Python3.x and Python2.x
# Has append and check functions
# When standalone, can read from either arguments or stdin
# Writes to stdout cleaner
# http://gist.github.com/eaydin
############################################
@eaydin
eaydin / Chunk String
Last active August 29, 2015 14:06
Split long String into lists with limited length
### useful when parsing strings to paragraphs
### to reassemble from lists with each element
### having a maximum length
### useful for low level reportlab pdf creation
### usage: stripLongString("My Very Extra Long String", maximumLengthINTEGER)
### Returns an array
def chunkstring(string, length):
#got this from http://stackoverflow.com/a/18854817/1278994
@eaydin
eaydin / python_print
Created February 15, 2012 13:57
SED Pattern to switch Python print statements to functions for 2->3
sed 's/print \"\(.*\)\"/print\(\"\1\"\)/' filename.py
@eaydin
eaydin / cronadd.sh
Created February 14, 2012 14:32
BASH scripting way of adding Cronjob
#!/bin/bash
command=”/path-to/my_process.sh > /dev/null 2>&1″
job=”*/5 * * * * $command”
cat <(grep -i -v “$command” <(crontab -l)) <(echo “$job”) | crontab -