Skip to content

Instantly share code, notes, and snippets.

Lorenz Lo Sauer lsauer

Block or report user

Report or block lsauer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lsauer
lsauer / gist:4086997
Created Nov 16, 2012
mp3 Joiner / Join mp3 files
View gist:4086997
#easy method of joining two mp3's [lsauer.com 2012 - lo sauer]
#the result is dirty since it contains the mp3 header and ID-tags, but most mp3 libs play these files without a hassle.
#use the resulting mp3 as input for AAC, Opus,.. conversion.
#Windows
type file1 file2 > outfile
copy /b file1 + file2 + ... file_n outfile
#Linux, Mac
cat file1 file2 > outfile
@lsauer
lsauer / fuzzy-search.sql
Last active Feb 2, 2020
FullText fuzzy searching in SQL / MySQL
View fuzzy-search.sql
#lo sauer, 2013 - www.lsauer.com
#see: http://www.lsauer.com/2013/05/mysql-fuzzy-searching-fulltext-queries.html
#Note: In MySQL SUBSTRING, the string-index starts at position 1
SELECT * FROM tablename
WHERE SOUNDEX(tablename_field)
LIKE CONCAT('%',SUBSTRING(SOUNDEX('Fuzti serch derm'),2),'%');
@lsauer
lsauer / kill_process_pid_windows_linux_mac.php
Last active Jan 21, 2020
PHP: kill a process by its process-id/pid in a platform- and library-independent manner
View kill_process_pid_windows_linux_mac.php
<?#!/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 / gist:2757250
Last active Jan 20, 2020
JavaScript : within a string, count the number of occurances of a character / character counting and string-position
View gist:2757250
//www.lsauer.com 2012
//Answer to:
//http://stackoverflow.com/questions/881085/count-the-number-of-occurances-of-a-character-in-a-string-in-javascript/10671743#10671743
//There are at least four ways. The best option, which should also be the fastest -owing to the native RegEx engine -, is placed at the top. //jsperf.com is currently down, otherwise I would provide you with performance statistics.
#1.
("this is foo bar".match(/o/g)||[]).length
//>2
#2.
"this is foo bar".split("o").length-1
@lsauer
lsauer / gist:1320437
Created Oct 27, 2011
A list of common HTTP header settings
View gist:1320437
// by jonas john, posted by lo sauer / lsauer.com; PUBLIC DOMAIN
// description: common http headers:
// Use this header instruction to fix 404 headers
// produced by url rewriting...
header('HTTP/1.1 200 OK');
// Page was not found:
header('HTTP/1.1 404 Not Found');
// Access forbidden:
@lsauer
lsauer / gist:5196979
Last active Dec 27, 2019
JavaScript List of selected MIME types (JSON)
View gist:5196979
//lsauer.com , lo sauer 2013
//JavaScript List of selected MIME types
//A comprehensive MIME List is available here: https://gist.github.com/lsauer/2838503
var mimeTypes =
{
'a' : 'application/octet-stream',
'ai' : 'application/postscript',
'aif' : 'audio/x-aiff',
'aifc' : 'audio/x-aiff',
'aiff' : 'audio/x-aiff',
@lsauer
lsauer / tsql_update_field_when_conditional_value_is_set_trigger.sql
Created Dec 8, 2013
MS-SQL Server/TSQL Trigger: Update a field only when a specific value is set, otherwise set a different condition
View tsql_update_field_when_conditional_value_is_set_trigger.sql
/*www.technical-programming.com, lo sauer 2013
Target: MS/Microsoft SQL Server 2005 or higher
description: Upon update, the rows's timestamp field is set to the current unix-timestamp,
unless the timestamp is NULL or Empty. If the timestamp field is supplied in the update
statement, the supplied value is set as is.
The tstamp field is defined as:
[__unixtimestamp] INT NULL
The primary key is defined as:
[ID] INT IDENTITY (1, 1) NOT NULL
@lsauer
lsauer / a-transform-change-switch-tag.js
Created Aug 25, 2014
JavaScript-transformTag: switch/change the HTML DOM tag type
View a-transform-change-switch-tag.js
//lsauer.com, 2012; rev. 2014 by lo sauer
//description: transformTag fully replaces a node by a different Tag, and re-attaches all children to the newly formed Tag
// Any desired EventHandlers must be re-attached manually
//@param tagIdOrElem: an HTMLElement Id-Name or an instance of any HTMLElement
//[@param tagType]: the HTML Tag Type. Default is 'span' (HTMLSpanElement)
function transformTag(tagIdOrElem, tagType){
var elem = (tagIdOrElem instanceof HTMLElement) ? tagIdOrElem : document.getElementById(tagIdOrElem);
if(!elem || !(elem instanceof HTMLElement))return;
var children = elem.childNodes;
@lsauer
lsauer / left-flexible-right-fixed.css
Created Feb 5, 2015
css: fixed width column to the right and flexible full-width left-column
View left-flexible-right-fixed.css
/* lsauer.com, 2015 */
.left-flexible-right-fixed .container {
height: auto;
overflow: hidden;
}
.left-flexible-right-fixed .left-inner{
width: 100%;
}
.left-flexible-right-fixed .right {
width: 180px;
@lsauer
lsauer / InChi.js
Created Oct 25, 2011
Regular Expressions for validating SMILES, InChi, InChiKey
View InChi.js
// International Chemical Identifier Regex, by lo sauer - lsauer.com
// Morphine InchI:
var x="InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1"
// applying an organic character-subset
// we could check for the length property, but in case of 0 matches 'null' is returned -> hence !!.. \ generally equal to Boolean(..)
!!x.trim().match(/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\/,pqbtmsih]{6,})$/ig)
>true
//generic:
x.trim().match(/^((InChI=)?[^J][0-9a-z+\-\(\)\\\/,]+)$/ig)
You can’t perform that action at this time.