Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@simonw
simonw / recover_source_code.md
Last active January 16, 2024 08:13
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
@mivade
mivade / tornadosse.py
Last active February 8, 2024 02:17
Tornado server-sent events
"""Demonstration of server-sent events with Tornado. To see the
stream, you can either point your browser to ``http://localhost:8080``
or use ``curl`` like so::
$ curl http://localhost:8080/events
"""
import signal
from tornado import web, gen
@Integralist
Integralist / 1. Setup.bash
Last active November 8, 2019 09:30
DynamoDB (using Spurious)
# http://boot2docker.io/
# https://github.com/stevenjack/spurious
boot2docker init
boot2docker up
spurious-server start
spurious init
spurious start

Install the netcat nc command with Homebrew (otherwise Mac OS X version is really old and the interface is different):

brew install netcat

Use netcat to listen for incoming TCP connections on port 3000:

nc -l -p 3000
@Integralist
Integralist / Rack Middleware.md
Created November 15, 2014 11:19
Rack Middleware
use Rack::Lint # gives more descriptive error messages when responses aren't valid

class LogIt
  def initialize(app)
    @app = app
  end
  def call(env)
    status, headers, body  = @app.call(env)
    body.map { |chunk| p "LogIt: #{chunk}" }
@Integralist
Integralist / 1. Designing Systems and Applications.md
Last active June 7, 2020 15:22
Designing Systems and Applications

Designing Systems and Applications

This is a short document of tips and notes I've accumulated while learning more about designing distributed systems and building concurrent applications. It is by no means definitive and merely scratches the surface of what is needed to be considered when designing an architecture expected to handle large scale traffic.

Distributed Systems

Scale out, not up

There reaches a point in your application's design where by merely throwing more hardware at the problem (i.e. "scaling up") will fail to resolve the scalability issues you're encountering.

@Integralist
Integralist / testing a ruby gem.md
Last active June 29, 2023 15:58
Testing a Ruby Gem

Version 1

# Long way of doing things (new files need to be added to staging area *before* building the gem)
git add . && gem build my_gem.gemspec && gem install my_gem-0.0.0.gem

Version 2

@Integralist
Integralist / 1. [CURRENT] Brew switch.md
Last active June 15, 2020 09:09
[Brew switch to custom versions of software] #homebrew #brew #install #versions #switch

If you wish to switch your python command to use a different Python interpreter (and it's a Python version you previously had installed using Homebrew):

brew info python           # To see what you have previously installed
brew switch python 3.x.x_x # Ex. 3.6.5_1

NOTE: this might not be wise to do as you might have other software that relies on the Python interpreter you have currently (i.e. before the switch).

Otherwise to install multiple Python versions using Homebrew (instead of something like pyenv)...

@Integralist
Integralist / Software Simplicity.md
Last active June 7, 2020 15:17
Software Simplicity
  • Simplicity !== Easy
  • Easy is short term and can sometimes even introduce complexity
  • Simplicity allows for easy while avoiding complexity
  • Complect == tangling/braiding together
  • Complexity is the result of something that has been complected
  • Untangle complected code (e.g. decoupling of components)
  • Do not chain calls (i.e. Law of Demeter)
  • Consider Channels as form of asynchronous flow control
  • Ask yourself all the time: "can this thing be moved? does it have well defined boundaries?"
@Integralist
Integralist / ruby string formatting.rb
Created August 22, 2014 08:45
Ruby string formatting functionality (like PHP's sprintf)
"foo-%s-baz" % "bar" # => "foo-bar-baz"
"foo-%s-baz" % 123 # => "foo-123-baz"