Skip to content

Instantly share code, notes, and snippets.

@mdmitry1
Last active October 25, 2025 14:14
Show Gist options
  • Save mdmitry1/464819af55a87be0dc200d7cd1ef0a56 to your computer and use it in GitHub Desktop.
Save mdmitry1/464819af55a87be0dc200d7cd1ef0a56 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3.14
'''
https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
https://www.codequoi.com/en/coloring-terminal-text-tput-and-ansi-escape-sequences
https://web.archive.org/web/20210226122732/http://ascii-table.com/ansi-escape-sequences.php
'''
from sys import argv
from argparse import ArgumentParser
def print_color(fg_bg_code, color):
print(fg_bg_code + color + "m " + color.ljust(4),end="")
def print_colors(fg_bg_code,palette):
for i in range(0, 256):
print_color(fg_bg_code, palette[i]);
if( i % 16 == 15): print(u"\033[0m")
def print_color_pair(c1, c2):
combined_code=u"\033[38;5;" + c1 + "m" + \
u"\033[48;5;" + c2 + "m "
c1c2=c1 + ":" + c2
print(combined_code + c1c2.ljust(7),end="")
def print_color_combinations(palette, r1, r2, c1, c2):
for i in range(r1, r2):
for j in range(c1, c2):
print_color_pair(palette[i],palette[j]);
if( j % 16 == 15 or j == c2 - 1): print(u"\033[0m")
colors=[]
[colors.append(str(i)) for i in range(0, 256)]
print_colors(u"\033[38;5;", colors)
print_colors(u"\033[48;5;", colors)
if len(argv) > 1:
parser = ArgumentParser()
parser.add_argument('--row1', '-r1', type=int, default=0)
parser.add_argument('--row2', '-r2', type=int, default=256)
parser.add_argument('--column1', '-c1', type=int, default=0)
parser.add_argument('--column2', '-c2', type=int, default=256)
args=parser.parse_args()
print_color_combinations(colors,args.row1, \
args.row2, \
args.column1, \
args.column2 )
combined_code=u"\033[38;5;200m" + u"\033[48;5;14m"
print(combined_code + u"\033[1m BOLD \033[0m")
print(combined_code + u"\033[2m Regular \033[0m")
print(combined_code + u"\033[3m Italic \033[0m")
print(combined_code + u"\033[4m Underline \033[0m")
print(combined_code + u"\033[5m Blink \033[0m")
print(combined_code + u"\033[7m Reversed \033[0m")
print(combined_code + u"\033[8m Concealed \033[0m")
print(combined_code + u"\033[9m Strikethrough \033[0m")
#!/usr/bin/bash -f
export MYVAR="MYVAL"
perlbin=/usr/bin/perl
if [ $# -ge 2 ]; then perlbin=$2; fi
#! -*-perl-*-
eval 'exec $perlbin -x -S $0 ${1+"$@"};'
if $running_under_some_shell;
use Data::Dumper;
use Math::Trig;
printf("running %s v(%vd)\n", $^X, $^V);
print Dumper \@ARGV;
print $ENV{MYVAR},"\n";
my $sum=0;
my $n=1e6;
$#ARGV >=0 ? $n = $ARGV[0] : print "n = $n\n";
for(my $i=1; $i < $n; $i++) {$sum += 6 / $i**2; }
print "\033[38;5;4m\033[48;5;7m", sqrt($sum)/pi-1, "\033[0m\n";
#!/usr/bin/tcsh -f
"/usr/bin/true" '''\'
if($#argv < 2 ) then
exec /usr/bin/python3.12 $0 $*
else
setenv PYTHONPATH /usr/local/lib/python3.14/site-packages
exec python3.14 $0 $*
endif
'''
from os import name as osname
from os.path import basename, realpath
from numpy import float64
from ctypes import *
from sys import argv, version
from rich import print as rprint
from re import sub
script_name=basename(realpath(argv[0]))
n = "1" if len(argv) < 2 else argv[1]
libc=cdll.msvcrt if 'nt' == osname else cdll.LoadLibrary("libc.so.6")
printf=libc.printf
print(sub('\n','',version))
printf(b"n = %s\n", n.encode('utf-8'))
libm=cdll.msvcrt if 'nt' == osname else cdll.LoadLibrary("libm.so.6")
sin=libm.sin
sin.argtypes=[c_double]
sin.restype=c_double
printf.argtypes = [c_char_p, c_double]
try:
printf(b"\033[38;5;4m\033[48;5;7m" + b"sin(n) = %18.16lf\033[0m\n", sin(float64(n)))
except Exception as err:
rprint("\n[magenta] " + script_name + ":", "[red] ERROR: [/red]", "[red] " + str(err), "\n")
exit(1)
<h1>Dillinger</h1>
<h2><em>The Last Markdown Editor, Ever</em></h2>
<p><a href="https://nodesource.com/products/nsolid"><img src="https://cldup.com/dTxpPi9lDf.thumb.png" alt="N|Solid" /></a></p>
<p><a href="https://travis-ci.org/joemccann/dillinger"><img src="https://travis-ci.org/joemccann/dillinger.svg?branch=master" alt="Build Status" /></a></p>
<p>Dillinger is a cloud-enabled, mobile-ready, offline-storage compatible,
AngularJS-powered HTML5 Markdown editor.</p>
<ul>
<li>Type some Markdown on the left</li>
<li>See HTML in the right</li>
<li>✨Magic ✨</li>
</ul>
<h2>Features</h2>
<ul>
<li>Import a HTML file and watch it magically convert to Markdown</li>
<li>Drag and drop images (requires your Dropbox account be linked)</li>
<li>Import and save files from GitHub, Dropbox, Google Drive and One Drive</li>
<li>Drag and drop markdown and HTML files into Dillinger</li>
<li>Export documents as Markdown, HTML and PDF</li>
</ul>
<p>Markdown is a lightweight markup language based on the formatting conventions
that people naturally use in email.
As [John Gruber] writes on the <a href="http://daringfireball.net/projects/markdown/">Markdown site</a></p>
<blockquote>
<p>The overriding design goal for Markdown's
formatting syntax is to make it as readable
as possible. The idea is that a
Markdown-formatted document should be
publishable as-is, as plain text, without
looking like it's been marked up with tags
or formatting instructions.</p>
</blockquote>
<p>This text you see here is *actually- written in Markdown! To get a feel
for Markdown's syntax, type some text into the left window and
watch the results in the right.</p>
<h2>Tech</h2>
<p>Dillinger uses a number of open source projects to work properly:</p>
<ul>
<li>[AngularJS] - HTML enhanced for web apps!</li>
<li>[Ace Editor] - awesome web-based text editor</li>
<li>[markdown-it] - Markdown parser done right. Fast and easy to extend.</li>
<li>[Twitter Bootstrap] - great UI boilerplate for modern web apps</li>
<li>[node.js] - evented I/O for the backend</li>
<li>[Express] - fast node.js network app framework [@tjholowaychuk]</li>
<li>[Gulp] - the streaming build system</li>
<li><a href="https://breakdance.github.io/breakdance/">Breakdance</a> - HTML
to Markdown converter</li>
<li>[jQuery] - duh</li>
</ul>
<p>And of course Dillinger itself is open source with a <a href="https://github.com/joemccann/dillinger">public repository</a>
on GitHub.</p>
<h2>Installation</h2>
<p>Dillinger requires <a href="https://nodejs.org/">Node.js</a> v10+ to run.</p>
<p>Install the dependencies and devDependencies and start the server.</p>
<p><code>sh
cd dillinger
npm i
node app
</code></p>
<p>For production environments...</p>
<p><code>sh
npm install --production
NODE_ENV=production node app
</code></p>
<h2>Plugins</h2>
<p>Dillinger is currently extended with the following plugins.
Instructions on how to use them in your own application are linked below.</p>
<p>| Plugin | README |
| ------ | ------ |
| Dropbox | <a href="https://github.com/joemccann/dillinger/tree/master/plugins/dropbox/README.md">plugins/dropbox/README.md</a> |
| GitHub | <a href="https://github.com/joemccann/dillinger/tree/master/plugins/github/README.md">plugins/github/README.md</a> |
| Google Drive | <a href="https://github.com/joemccann/dillinger/tree/master/plugins/googledrive/README.md">plugins/googledrive/README.md</a> |
| OneDrive | <a href="https://github.com/joemccann/dillinger/tree/master/plugins/onedrive/README.md">plugins/onedrive/README.md</a> |
| Medium | <a href="https://github.com/joemccann/dillinger/tree/master/plugins/medium/README.md">plugins/medium/README.md</a> |
| Google Analytics | <a href="https://github.com/RahulHP/dillinger/blob/master/plugins/googleanalytics/README.md">plugins/googleanalytics/README.md</a> |</p>
<h2>Development</h2>
<p>Want to contribute? Great!</p>
<p>Dillinger uses Gulp + Webpack for fast developing.
Make a change in your file and instantaneously see your updates!</p>
<p>Open your favorite Terminal and run these commands.</p>
<p>First Tab:</p>
<p><code>sh
node app
</code></p>
<p>Second Tab:</p>
<p><code>sh
gulp watch
</code></p>
<p>(optional) Third:</p>
<p><code>sh
karma test
</code></p>
<h4>Building for source</h4>
<p>For production release:</p>
<p><code>sh
gulp build --prod
</code></p>
<p>Generating pre-built zip archives for distribution:</p>
<p><code>sh
gulp build dist --prod
</code></p>
<h2>Docker</h2>
<p>Dillinger is very easy to install and deploy in a Docker container.</p>
<p>By default, the Docker will expose port 8080, so change this within the
Dockerfile if necessary. When ready, simply use the Dockerfile to
build the image.</p>
<p><code>sh
cd dillinger
docker build -t &lt;youruser&gt;/dillinger:${package.json.version} .
</code></p>
<p>This will create the dillinger image and pull in the necessary dependencies.
Be sure to swap out <code>${package.json.version}</code> with the actual
version of Dillinger.</p>
<p>Once done, run the Docker image and map the port to whatever you wish on
your host. In this example, we simply map port 8000 of the host to
port 8080 of the Docker (or whatever port was exposed in the Dockerfile):</p>
<p><code>sh
docker run -d -p 8000:8080 --restart=always --cap-add=SYS_ADMIN --name=dillinger &lt;youruser&gt;/dillinger:${package.json.version}
</code></p>
<blockquote>
<p>Note: <code>--capt-add=SYS-ADMIN</code> is required for PDF rendering.</p>
</blockquote>
<p>Verify the deployment by navigating to your server address in
your preferred browser.</p>
<p><code>sh
127.0.0.1:8000
</code></p>
<h2>License</h2>
<p>MIT</p>
<p><strong>Free Software, Hell Yeah!</strong></p>
#!/usr/bin/python3.14
import sys
# Completely replace sys.path
sys.path = ['', '/usr/lib/python3.14', '/usr/lib/python3.14/lib-dynload',
'/usr/local/lib/python3.14/site-packages', '/usr/lib/python3.14/site-packages' ]
from argparse import ArgumentParser
from schwifty import IBAN
import sys
from os import _exit
from rich.console import Console
console_256=Console(color_system="256")
parser = ArgumentParser()
parser.add_argument('--bank', '-bnk', required=True)
parser.add_argument('--branch', '-brn', required=True)
parser.add_argument('--account', '-n', required=True)
args=parser.parse_args()
if not args.bank.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: bank code should contain digits only\n")
_exit(-1)
if not args.branch.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: branch code should contain digits only\n")
_exit(-1)
if not args.account.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: account number should contain digits only\n")
_exit(-1)
if len(args.bank) > 2:
console_256.print("[red on cornsilk1]" + "\nERROR: bank code exceeds maximum size of 2\n")
_exit(-1)
if len(args.branch) > 3:
console_256.print("[red on cornsilk1]" + "\nERROR: branch code exceeds maximum size of 3\n")
_exit(-1)
if len(args.account) > 8:
console_256.print("[red on cornsilk1]" + "\nERROR: account number exceeds maximum size of 8\n")
_exit(-1)
try:
iban=IBAN.generate("IL", bank_code=args.bank, branch_code=args.branch, account_code=args.account)
console_256.print("[dark_blue on white]" + iban[0:4] + " " + iban[4:8] + " " + iban[8:12] + " " + iban[12:16] + " " + iban[16:20] + " " + iban[20:23])
except:
print("Unexpected error:", sys.exc_info()[0])
#!/usr/bin/python3.12
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from sys import argv
from os.path import basename
from rich.console import Console
console_256=Console(color_system="256")
usage = "\n " + basename(argv[0])
usage = usage + " <-bnk|--bank> <bank code>"
usage = usage + " <-brn|--branch> <branch number> "
usage = usage + " <-n|--account> <account_number>"
usage = usage + "\n Example:"
usage = usage + "\n " + basename(argv[0])
usage = usage + " -bnk 10 -brn 800 -n 99999999"
usage = usage + "\n Result: \033[38;5;4m\033[48;5;7mIL62 0108 0000 0009 9999 999\033[0m"
parser = ArgumentParser( prog=argv[0], usage=usage, description = "Calculates IBAN for Israel bank accounts",
formatter_class=RawDescriptionHelpFormatter,
epilog=(' <bank code>: 2 digits' + '\n' +
' <branch number>: 2 or 3 digits' + '\n' +
' <account number>: not more than 8 digits'''))
if len(argv)==1:
parser.print_help()
exit(1)
parser.add_argument('--bank', '-bnk', required=True )
parser.add_argument('--branch', '-brn', required=True )
parser.add_argument('--account', '-n', required=True )
args=parser.parse_args()
if not args.bank.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: bank code should contain digits only\n")
exit(-1)
if not args.branch.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: branch code should contain digits only\n")
exit(-1)
if not args.account.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: account number should contain digits only\n")
exit(-1)
if len(args.bank) > 2:
console_256.print("[red on cornsilk1]" + "\nERROR: bank code exceeds maximum size of 2\n")
exit(-1)
if len(args.branch) > 3:
console_256.print("[red on cornsilk1]" + "\nERROR: branch code exceeds maximum size of 3\n")
exit(-1)
if len(args.account) > 8:
console_256.print("[red on cornsilk1]" + "\nERROR: account number exceeds maximum size of 8\n")
exit(-1)
full_account_number=args.bank + args.branch.zfill(3) + args.account.zfill(13);
control_number = 98 - int(full_account_number + "182100") % 97
iban="IL" + str(control_number).zfill(2) + full_account_number.zfill(19)
console_256.print("[dark_blue on white]" + iban[0:4] + " " + iban[4:8] + " " + iban[8:12] + " " + iban[12:16] + " " + iban[16:20] + " " + iban[20:23])
#!/usr/bin/python3.14
import sys
# Completely replace sys.path
sys.path = ['', '/usr/lib/python3.14', '/usr/lib/python3.14/lib-dynload',
'/usr/local/lib/python3.14/site-packages', '/usr/lib/python3.14/site-packages' ]
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from sys import argv
from os.path import basename
from rich.console import Console
console_256=Console(color_system="256")
usage = "\n " + basename(argv[0])
usage = usage + " <-bnk|--bank> <bank code>"
usage = usage + " <-brn|--branch> <branch number> "
usage = usage + " <-n|--account> <account_number>"
usage = usage + "\n Example:"
usage = usage + "\n " + basename(argv[0])
usage = usage + " -bnk 10 -brn 800 -n 99999999"
usage = usage + "\n Result: \033[38;5;4m\033[48;5;7mIL62 0108 0000 0009 9999 999\033[0m"
parser = ArgumentParser( prog=argv[0], usage=usage, description = "Calculates IBAN for Israel bank accounts",
formatter_class=RawDescriptionHelpFormatter,
epilog=(' <bank code>: 2 digits' + '\n' +
' <branch number>: 2 or 3 digits' + '\n' +
' <account number>: not more than 8 digits'''))
if len(argv)==1:
parser.print_help()
exit(1)
parser.add_argument('--bank', '-bnk', required=True )
parser.add_argument('--branch', '-brn', required=True )
parser.add_argument('--account', '-n', required=True )
args=parser.parse_args()
if not args.bank.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: bank code should contain digits only\n")
exit(-1)
if not args.branch.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: branch code should contain digits only\n")
exit(-1)
if not args.account.isdigit():
console_256.print("[red on cornsilk1]" + "\nERROR: account number should contain digits only\n")
exit(-1)
if len(args.bank) > 2:
console_256.print("[red on cornsilk1]" + "\nERROR: bank code exceeds maximum size of 2\n")
exit(-1)
if len(args.branch) > 3:
console_256.print("[red on cornsilk1]" + "\nERROR: branch code exceeds maximum size of 3\n")
exit(-1)
if len(args.account) > 8:
console_256.print("[red on cornsilk1]" + "\nERROR: account number exceeds maximum size of 8\n")
exit(-1)
full_account_number=args.bank + args.branch.zfill(3) + args.account.zfill(13);
control_number = 98 - int(full_account_number + "182100") % 97
iban="IL" + str(control_number).zfill(2) + full_account_number.zfill(19)
console_256.print("[dark_blue on white]" + iban[0:4] + " " + iban[4:8] + " " + iban[8:12] + " " + iban[12:16] + " " + iban[16:20] + " " + iban[20:23])
#!/usr/bin/tcsh -f
"/bin/true" '''\'
chmod 700 /run/user/* >& /dev/null
setenv QTWEBENGINE_CHROMIUM_FLAGS "--disable-gpu"
exec /usr/bin/python3.12 $0 $*
'''
from PyQt5.QtWidgets import QApplication, QMainWindow
import PyQt5.QtWebEngineWidgets
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl
from sys import argv
from os.path import dirname, realpath
import sys
app = QApplication(sys.argv)
window = QMainWindow()
view = QWebEngineView()
window.setCentralWidget(view)
# Load HTML from a local file
if(len(sys.argv) > 1 ):
html=realpath(sys.argv[1])
else:
html=dirname(realpath(argv[0])) + "/example1_md.html"
view.load(QUrl.fromLocalFile( html ))
# Or load HTML content directly
# view.setHtml("<h1>Hello from PyQt5!</h1>")
window.show()
sys.exit(app.exec_())
#!/usr/bin/tcsh -f
setenv MYVAR "MYVAL"
set perlbin=/usr/bin/perl
if($#argv > 1 ) set perlbin=$2
@ i = 0
set args=`echo '$'$i`
while($i < $#argv)
@ i = $i + 1
set args=`echo $args '$'$i`
end
#!perl
eval "exec $perlbin -x -S $args;"
if $running_under_some_shell;
use Data::Dumper;
use Math::Trig;
printf("running %s v(%vd)\n", $^X, $^V);
print Dumper \@ARGV;
print $ENV{MYVAR},"\n";
my $sum=0;
my $n=1e6;
$#ARGV >=0 ? $n = $ARGV[0] : print "n = $n\n";
for(my $i=1; $i < $n; $i++) {$sum += 6 / $i**2; }
print "\033[38;5;4m\033[48;5;7m", sqrt($sum)/pi-1, "\033[0m\n";
#!/usr/bin/tcsh -f
#\
setenv MYVAR MYVAL
#\
exec /usr/bin/tclsh $0 $*
proc setBit {var bit} {
upvar 1 $var v
# OR
set v [expr {$v | (1 << $bit)}]
}
proc lshift {listVar {count 1}} {
upvar 1 $listVar l
if {![info exists l]} {
# make the error message show the real variable name
error "can't read \"$listVar\": no such variable"
}
if {![llength $l]} {error Empty}
set r [lrange $l 0 [incr count -1]]
set l [lreplace $l [set l 0] $count]
return $r
}
if {![llength $argv]} {
set args {120 0 1 2}
} else {
set args [split $argv]
}
set v [lshift args]
puts "MYVAR=$env(MYVAR)"
puts "\033\[38;5;4m\033\[48;5;7m$v\033\[0m"
while { [llength $args] > 0 } {
setBit v [lshift args]
puts "\033\[38;5;4m\033\[48;5;7m$v\033\[0m"
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment