Skip to content

Instantly share code, notes, and snippets.

View lsauer's full-sized avatar
🎯
Focusing

Lorenz Lo Sauer lsauer

🎯
Focusing
View GitHub Profile
@lsauer
lsauer / masterpanel.md
Last active December 27, 2015 06:28
Show a master Panel of all control panel Settings / Actions in Windows-Explorer (Windows 7)
lsauer.com, 2013 via http://tuxx-home.at/
See: http://en.wikipedia.org/wiki/Windows_Master_Control_Panel_shortcut

  • Create a folder with the CLSID {ed7ba470-8e54-465e-825c-99712043e01c}: "GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}"
  • Open it in Windows Explorer.
@lsauer
lsauer / pathfix.cs
Created October 21, 2013 08:10
C# / csharp: fix slashes and backslashes in an url path (e.g. REST)
//lsauer.com, 2013
//descr: fix slashes and backslashes in an url;
public static class StringExtension
{
public static string FixPathSlashes(this string url) {
var ret = System.Text.RegularExpressions.Regex.Replace(url, @"([^:][/|\\]\s*[/|\\]+|\\)", "/");
ret = ret.Trim('/', '\\', ' ', '\n');
return ret;
}
}
@lsauer
lsauer / get_path_StreamWriter.cs
Created September 14, 2013 06:57
c#: Directly getting / setting the filename and path of a StreamWriter
//lsauer.com, 2013
//Description: conveniently setting and getting the a Filebased StreamWriter,
// without an extra class-variable e.g. 'filename'
class SomeClass
{
protected System.IO.StreamWriter _logfile = null;
public string LogFile {
get{ return ((FileStream)(_logfile.BaseStream)).Name; }
set{ if(value == null){ _logfile.Close(); _logfile = null; }
@lsauer
lsauer / description.md
Created September 10, 2013 17:46
Python / json module - ValueError: Expecting property name: line 1 column 1 (char 0) or line 1 column 1 (char 1)
@lsauer
lsauer / kill_process_pid_windows_linux_mac.php
Last active January 21, 2020 21:30
PHP: kill a process by its process-id/pid in a platform- and library-independent manner
<?#!/usr/bin/php5
# www.lsauer.com, 2012 lo sauer
# desc: kill a process on Linux, MacOS, Windows without a process-control library
# in the php setup or environment
$kill = function($pid){ return stripos(php_uname('s'), 'win')>-1
? exec("taskkill /F /PID $pid") : exec("kill -9 $pid");
};
//e.g.
echo $kill(19008);
//> "Successfully terminated...."
@lsauer
lsauer / boolean_to_string_format.php
Last active May 30, 2016 21:45
PHP: Coerce / Convert boolean value to readable string format
<?//lsauer.com
//desc: 'false' converted into a string returns an empty string
// assert((string)$boolvariable == '', '"false" converted into a <string> does not return an empty string')
// assert((string)$boolvariable == '', '"true" converted into a <string> does not return "1"')
//related to: http://stackoverflow.com/questions/7336861/how-to-convert-string-to-boolean-php
//example
echo $boolvariable ? 'true' : 'false';
echo $arrayvariable['somkeyvaluelevel1']['somekeyvaluelevel2'] ? $arrayvariable['somkeyvaluelevel1']['somekeyvaluelevel2'] 'true' : 'false';
@lsauer
lsauer / ssh_disable_timeout.sh
Created September 3, 2013 19:27
Linux : Do not timeout SSH Sessions
$ sudo nano /etc/ssh/sshd_config
#Add/Change
TCPKeepAlive no
#add for when KeepAlive is used
ClientAliveInterval 30
ClientAliveCountMax 99999
$ sudo service ssh restart
#optional 'screen': Full-screen window manager that multiplexes a physical terminal
@lsauer
lsauer / examples_list_comprehensions.py
Created September 2, 2013 19:08
Python: Understanding and constructing list comprehensions
# www.lsauer.com, lo sauer 2013
#desc: blog post - examples of list comprehensions hoc comprehensions anywhere
#ITER... any iterable implementing __iter__ and next()
#COND... any boolean condition or expression evaluating to a boolean value
list(ex for ex in ITER if COND)
#the first element matching the condition
next(ex for ex in xrange(10) if ex > 4) #> 0
xfunc = lambda *args: (ei for ei in xrange(*args))
@lsauer
lsauer / import_performance.sql
Created September 2, 2013 09:10
Slow MySQL: Import on windows taking forever / import performance tuning
#lsauer.com, 2013
#1. export using BULK INSERTs instead of single INSERT(...) statements
#At the top of the file add:
SET autocommit=0;
#at the end of the file
COMMIT;
#turn off FK,UK checking
#see: http://dev.mysql.com/doc/refman/5.0/en/innodb-tuning.html
@lsauer
lsauer / flatten_list_recursion.py
Last active December 22, 2015 01:38
python -methods : flatten a nested list of an arbitrary depth ( recursive and depth-iteration)
#www.lsauer.com - 2013, lo sauer 2013
#desc: cannonical examples for recursive and stacked list flattening
#1. Recursion:
def flatten(iterable,parent=None or []):
#parent=None or [] => #required as default argument pointers are mutable and stored outside the function stack
#accessed via flatten.func_defaults
for el in iterable:
if hasattr(el, '__iter__') and not type(el) in (str, bytes, bytearray, buffer, unicode):
flatten(el, parent)