Skip to content

Instantly share code, notes, and snippets.

@albertstartup
albertstartup / recover_source_code.md
Created March 12, 2017 04:39 — 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
@albertstartup
albertstartup / makeshiftmatrix.py
Created December 15, 2016 19:54
make shift matrix using list comprehension
def makeshiftmatrix(upper_or_lower, row, column):
return [[1 if item_idx == row_idx+upper_or_lower else 0 for item_idx in range(0, column)] for row_idx in range(0, row)]
@albertstartup
albertstartup / bash-history-to-zsh-history.py
Created October 31, 2016 07:24 — forked from dllud/bash-history-to-zsh-history.py
Import bash history (has no timestamps) to zsh history.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This is how I used it:
# $ cat ~/.bash_history | python bash-history-to-zsh-history.py >> ~/.zsh_history
import sys
import time
def main():
@albertstartup
albertstartup / tf_lstm.py
Created October 4, 2016 03:42 — forked from siemanko/tf_lstm.py
Simple implementation of LSTM in Tensorflow in 50 lines (+ 130 lines of data generation and comments)
"""Short and sweet LSTM implementation in Tensorflow.
Motivation:
When Tensorflow was released, adding RNNs was a bit of a hack - it required
building separate graphs for every number of timesteps and was a bit obscure
to use. Since then TF devs added things like `dynamic_rnn`, `scan` and `map_fn`.
Currently the APIs are decent, but all the tutorials that I am aware of are not
making the best use of the new APIs.
Advantages of this implementation:
# author: Aaditya Prakash
# usage:
# python programs_on_gpu.py
# Sample Output
#GPU_ID GPU_MEM USER PGRP PID %CPU %MEM STARTED TIME COMMAND
#----- ------- ---- ---- --- ---- ---- ------- ---- -------
#1 11738MiB ap 25640 25640 158 2.4 00:47:15 00:43:01 python train.py
#2 11843MiB ap 23806 23806 99.4 2.0 00:46:22 00:27:50 python cifar10_cnn.py
@albertstartup
albertstartup / .block
Last active August 10, 2016 06:29
mayan_numbers
height: 800
@albertstartup
albertstartup / reset-defcustom-var.el
Created August 8, 2016 02:49
Reset defcustom variable
(defun reset-defcustom-var (var)
(set var (eval (car (get var 'standard-value)))))
@albertstartup
albertstartup / enable-hideshow.el
Created August 5, 2016 14:06
Enable hideshow mode.
;;; enable-hideshow.el --- Enable hideshow mode.
(add-hook 'prog-mode-hook 'hs-minor-mode)
(provide 'enable-hideshow)
@albertstartup
albertstartup / blank-stage.el
Last active August 5, 2016 12:08
Blank stage.
;;; blank-stage.el --- Blank stage.
(menu-bar-mode -1)
(setq initial-scratch-message "")
(setq inhibit-startup-message t)
(provide 'blank-stage)
@albertstartup
albertstartup / enable-narrowing.el
Last active August 5, 2016 12:03
Enable narrowing.
;;; enable-narrowing.el --- Enable narrowing.
(put 'narrow-to-defun 'disabled nil)
(put 'narrow-to-page 'disbled nil)
(put 'narrow-to-region 'disabled nil)
(provide 'enable-narrowing)