Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@simonw
simonw / recover_source_code.md
Last active Oct 26, 2020
How to recover lost Python source code if it's still resident in-memory
View recover_source_code.md

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 Oct 7, 2020
Tornado server-sent events
View tornadosse.py
"""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 Nov 8, 2019
DynamoDB (using Spurious)
View 1. Setup.bash
# http://boot2docker.io/
# https://github.com/stevenjack/spurious
boot2docker init
boot2docker up
spurious-server start
spurious init
spurious start
View Netcat.md

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
View Rack Middleware.md
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 Jun 7, 2020
Designing Systems and Applications
View 1. Designing Systems and Applications.md

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.

View testing a ruby gem.md

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 Jun 15, 2020
[Brew switch to custom versions of software] #homebrew #brew #install #versions #switch
View 1. [CURRENT] Brew switch.md

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)...

View Software Simplicity.md
  • 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 Aug 22, 2014
Ruby string formatting functionality (like PHP's sprintf)
View ruby string formatting.rb
"foo-%s-baz" % "bar" # => "foo-bar-baz"
"foo-%s-baz" % 123 # => "foo-123-baz"
You can’t perform that action at this time.