Skip to content

Instantly share code, notes, and snippets.

@pydemo
pydemo / recover_source_code.md
Created April 9, 2018 21:00 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@pydemo
pydemo / recover_source_code.md
Created April 9, 2018 21:00 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@pydemo
pydemo / build.sbt
Created May 17, 2018 19:28 — forked from bartschuller/build.sbt
Using Scala's Dynamic trait and reflection to implement delegation. If we swap reflection for macros it will be fast and typesafe again. I guess this could then replace the AutoProxy compiler plugin.
name := "delegation"
scalaVersion := "2.10.0"
libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _)
@pydemo
pydemo / dir.scala
Created May 22, 2018 14:33 — forked from dajobe/dir.scala
Get the methods on a class / object - aka python dir()
// Inspired by http://stackoverflow.com/questions/2886446/how-to-get-methods-list-in-scala
def dir(x: AnyRef): Unit = println(x.getClass.getMethods.map(_.getName).distinct.sorted.mkString(" "))
scala> dir("")
charAt codePointAt codePointBefore codePointCount compareTo compareToIgnoreCase concat contains contentEquals copyValueOf endsWith equals equalsIgnoreCase format getBytes getChars getClass hashCode indexOf intern isEmpty lastIndexOf length matches notify notifyAll offsetByCodePoints regionMatches replace replaceAll replaceFirst split startsWith subSequence substring toCharArray toLowerCase toString toUpperCase trim valueOf wait
@pydemo
pydemo / ArithmeticParser.scala
Created July 13, 2018 14:44 — forked from daixque/ArithmeticParser.scala
Arithmetic parser/evaluator written in scala using parser combinator
import scala.util.parsing.combinator._
abstract class Value {
def eval():Double
}
case class Number(n:Double) extends Value {
def eval():Double = n
}
case class Binomial(op: String, v1:Value, v2:Value) extends Value {
def eval():Double = op match {
@pydemo
pydemo / genshim.cpp
Created August 29, 2018 15:21 — forked from nohbdy/genshim.cpp
Shim DLL Generation
// Code originally found on http://www.hulver.com/scoop/story/2006/2/18/125521/185
// Created by Rogerborg
#include <stdio.h>
#include <windows.h>
#include <list>
using namespace std;
// Change this to the name of the DLL that you want to clone
#define CLONE_DLL "WS2_32"
@pydemo
pydemo / dec.py
Created January 25, 2019 18:23 — forked from nmarley/dec.py
AWS KMS encryption/decryption using Python/Boto3
import boto3
import base64
if __name__ == '__main__':
session = boto3.session.Session()
kms = session.client('kms')
encrypted_password = 'AQECAHjgTiiE7TYRGp5Irf8jQ3HzlaQaHGYgsUJDaavnHcFm0gAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDDwxVQuG0oVwpkU7nQIBEIAoVGk1/wpserb+GVUOzE7PiL/Nr9fTDFKZfpKpF0ip2ct4B2q0Wn6ZZw=='
binary_data = base64.b64decode(encrypted_password)
@pydemo
pydemo / print_progress.py
Created June 12, 2019 13:50 — forked from aubricus/License
Python Progress Bar
# -*- coding: utf-8 -*-
# Print iterations progress
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
@pydemo
pydemo / cntlm-setup-win-lin.md
Created April 29, 2020 21:19 — forked from goude/cntlm-setup-win-lin.md
Minimal setup instructions for cntlm (Windows/Linux)

Minimal setup instructions for cntlm (Windows/Linux)

Problem

λ git clone https://github.com/mbostock/d3.git
Cloning into 'd3'...
fatal: unable to access 'https://github.com/mbostock/d3.git/':
Failed to connect to github.com port 443: Connection refused

Solution

@pydemo
pydemo / cntlm_npm.md
Created April 29, 2020 21:20 — forked from triskell/cntlm_npm.md
[Windows 7] CNTLM and NPM behind NTLM proxy

CNTLM and NPM behind NTLM proxy on Windows 7

CNTLM

  • Install CNTLM in a folder where you have full rights to run it as administrator.

  • Open cntlm.ini and fill it :

Username    YOUR_USERNAME
Domain YOUR_DOMAIN