Skip to content

Instantly share code, notes, and snippets.

@zhangz
zhangz / recover_source_code.md
Created April 2, 2017 13:21 — 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
@zhangz
zhangz / bobp-python.md
Created April 4, 2017 01:16 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@zhangz
zhangz / ArrayPool.cs
Created June 4, 2017 05:58 — forked from christiannagel/ArrayPool.cs
Show memory address of array
unsafe private static void ShowAddress(string name, int[] item)
{
fixed (int* addr = item)
{
Console.Write($"\t0x{(ulong)addr:X}");
}
}
@zhangz
zhangz / on-tail-recursion.md
Created July 14, 2018 12:10 — forked from mrange/on-tail-recursion.md
On the topic of tail calls in .NET

On the topic of tail calls in .NET

Let's say you have implemented a small data pipeline library to replace LINQ.

module TrivialStream =
  type Receiver<'T> = 'T            -> unit
  type Stream<'T>   = Receiver<'T>  -> unit

  module Details =
using System;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Double.Factorization;
namespace PolyRegressionCoefficients
{
class Program
{
public static void DrawRegression(double[] coeffs, double[] xList)