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 / gist:3741940
Created September 18, 2012 08:07
C# Fullscreen Console on Windows via unmanaged kernel32 calls to SetConsoleDisplayMode
//author: lsauer.com 2012, CC-BY-SA
//description: Fullscreen consoles were common until the last few years.
// Currently Windows XP, and Windows Vista, Windows 7’s Safe Mode allow fullscreen console mode.
// The reason is that the current display driver model does not support VGA text mode programs.
using System;
using System.IO;
using System.Collections.Generic; //for dictionary
using System.Runtime.InteropServices; //for P/Invoke DLLImport
class App
@lsauer
lsauer / gist:2834199
Created May 30, 2012 06:58
Windows Environment Variables / PATH variables
//www.lsauer.com 2012
//author: Microsoft Inc.
//Type: tab-separated flatfile / datatable
Variable Type Description
%ALLUSERSPROFILE% Local Returns the location of the All Users Profile.
%APPDATA% Local Returns the location where applications store data by default.
%CD% Local Returns the current directory string.
%CMDCMDLINE% Local Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% System Returns the version number of the current Command Processor Extensions.
@lsauer
lsauer / fuzzy-search.sql
Last active December 7, 2023 23:58
FullText fuzzy searching in SQL / MySQL
#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 / InChi.js
Created October 25, 2011 14:13
Regular Expressions for validating SMILES, InChi, InChiKey
// 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)
@lsauer
lsauer / textanim.html
Created June 1, 2012 09:13
JavaScript - Pure Text based animation fun with Unicodes / ASCII
<html><head></head><body>
<div id="timer">◉</div>
</body></html>
@lsauer
lsauer / converter.coffee
Created May 18, 2012 09:36
JavaScript / Coffeescript : Lightweight Conversion of HTML Entities to ASCII / ASCII 2 HTML
html2ascii = (asciis) ->
asciis.map (e, i, a) ->
String.fromCharCode HTML_ENTITIES.indexOf(e) if -1 isnt HTML_ENTITIES.indexOf(e)
ascii2html = (asciis) ->
asciis.map (e, i, a) ->
String.fromCharCode +e if HTML_ENTITIES.hasOwnProperty(e)
HTML_ENTITIES = Array(255)
HTML_ENTITIES["34"] = "&quot;"
HTML_ENTITIES["38"] = "&amp;"
HTML_ENTITIES["39"] = "&#39;"
@lsauer
lsauer / coffeescript-tutorial.md
Created June 7, 2012 14:31
CoffeeMug - a concise, hands-on CoffeeScript Tutorial

#CoffeeMug - A concise, hands-on CoffeeScript Tutorial

! Now delivered with a cup of hot Coffee

author: Lorenz Lo Sauer 2011 ( http://www.lsauer.com , @sauerlo), CC-BY-SA 3

description: a concise tutorial for JavaScript, R or Python programmers

about: CoffeeScript (CS), released in 2010 by J. Ashkenas (@jashkenas), is dynamically typed, interpreted programming language. It is takes syntax inspirations from popular dynamic languages such as Haskell, JavaScript, Erlang, Perl, Python, Ruby and even YAML.

@lsauer
lsauer / gist:5196979
Last active June 7, 2023 08:12
JavaScript List of selected MIME types (JSON)
//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 / split_after_n_words.js
Created May 20, 2012 20:11
C# / JavaScript - Splitting a string / sequence into parts of equal length ; split after n number of characters ; split sequence into GFF / FASTA like structure
//www.lsauer.com 2012
//FASTA linear sequence
"MEIEKSNNGGSNPSAGEEFKDMIKGVTKFLMMVIFLGTIMLWIMMPTLTYRTKWLPHLRIKFGTSTYFGATGTTLFMYMFPMMVVACLGCVYLHFKNRKSPHHIDRETKGGVWSKLRKPMLVKGPLGIVSVTEITFLAMFVALLLWCFITYLRNSFATITPKSAAAHDESLWQAKLESAALRLGLIGNICLAFLFLPVARGSSLLPAMGLTSESSIKYHIWLGHMVMALFTVHGLCYIIYWASMHEISQMIMWDTKGVSNLAGEIALAAGLVMWATTYPKIRRRFFEVFFYTHYLYIVFMLFFVLHVGISFSFIALPGFYIFLVDRFLRFLQSRENVRLLAARILPSDTMELTFSKNSKLVYSPTSIMFVNIPSISKLQWHPFTITSSSKLEPEKLSIVIKKEGKWSTKLHQRLSSSDQIDRLAVSVEGPYGPASADFLRHEALVMVCGGSGITPFISVIRDLIATSQKETCKIPKITLICAFKKSSEISMLDLVLPLSGLETELSSDINIKIEAFITRDNDAGDEAKAGKIKTLWFKPSLSDQSISSILGPNSWLWLGAILASSFLIFMIIIGIITRYYIYPIDHNTNKIYSLTSKTIIYILVISVSIMATCSAAMLWNKKKYGKVESKQVQNVDRPSPTSSPTSSWGYNSLREIESTPQESLVQRTNLHFGERPNLKKLLLDVEGSSVGVLVCGPKKMRQKVAEICSSGLAENLHFESISFSW"
.split(/(.{50})/gm).filter(Boolean)
//there is also the neat CSS 'word-break:break-all;' - property and word-wrap, but neither will let you specify the exact amount of character to break to.
//result - useful for FASTA splitting
["MEIEKSNNGGSNPSAGEE
@lsauer
lsauer / gist:2757250
Last active October 10, 2022 03:06
JavaScript : within a string, count the number of occurances of a character / character counting and string-position
//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