Skip to content

Instantly share code, notes, and snippets.

View dmgolembiowski's full-sized avatar

David M. Golembiowski dmgolembiowski

View GitHub Profile
@dmgolembiowski
dmgolembiowski / md5.js
Created June 3, 2020 03:21 — forked from MichaelPote/md5.js
invalid reference fix and fixed add32 not being overwritten properly.
/*
* http://www.myersdaily.org/joseph/javascript/md5-text.html
*/
(function (global) {
var md5cycle = function (x, k) {
var a = x[0],
b = x[1],
c = x[2],
d = x[3];
MODULE_ROOT_DIRECTORY = "my_app" # ./my_app/__main__.py
HAS_REQUIREMENTS = False
def make_dist():
return default_python_distribution()
def make_exe(dist):
policy = dist.make_python_packaging_policy()
policy.allow_files = True
policy.bytecode_optimize_level_one = True
@dmgolembiowski
dmgolembiowski / build-linux.sh.j2
Created June 12, 2021 06:11
Build Release Rust
#!/bin/sh
set -e
cargo +stable build --release --target i686-unknown-linux-gnu
cp -f target/i686-unknown-linux-gnu/release/{{ pkg.exe }} {{ pkg.exe }}-linux-x86
strip {{ pkg.exe}}-linux-x86
sha512sum {{ pkg.name }}-linux-x86 > {{ pkg.name }}-linux-x86.sha512
sha512sum -c {{ pkg.name }}-linux-x86.sha512 >/dev/null
cargo +stable build --release --target x86_64-unknown-linux-gnu
@dmgolembiowski
dmgolembiowski / logging-template.py
Created June 18, 2021 18:10
Don't want to rewrite this every time
try:
import os
import sys
import logging
except:
pass
class protolog(object):
subject = "project.log"
lvl = logging.DEBUG

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

#!/usr/bin/env python3
demo = [[ 1, 2 ], [3, 4, 5], [6, 7, 8, 9]]
flattened = []
[
flattened.extend(smol_list)
for smol_list in demo
]
demo = flattened

I had a quick comment/question about 2.5.1's Avoid Managing An Index Variable:

It's common [in] many languages to loop through things by using a temporary variable that's incremented... A Rust version of that pattern would be this snippet:

let collection = [1, 2, 3, 4, 5];
for i in 0..collection.len() {
  let item = collection[i];
  // ...
}
class GroupMirrorLDAP(BaseBackend):
"""
This is a hack to retrieve user groups for a user without having
"""
# ---------------------------------------------------------
def get_full_cn(self, cwid):
"""
use the control user to get get complete CN for django user
"""
@dmgolembiowski
dmgolembiowski / p2p-bot.py
Created September 10, 2021 01:56
Full service P2P and file upload bot. Requires Python v3.7.4.
#!/usr/bin/env python
import aiofiles
import tarfile
import pathlib
import uuid
import os
import asyncio
import functools
import logging
import random
#!/usr/bin/env python
# Using Python v3.7.4
from imap_tools import (AND, MailBox)
import aiofiles
import tarfile
import pathlib
import uuid
import os
import asyncio
import functools