Skip to content

Instantly share code, notes, and snippets.

View davidbegin's full-sized avatar

Begin davidbegin

View GitHub Profile
@davidbegin
davidbegin / thread_quiz.rb
Created September 25, 2015 06:14
Thread#kill Thread#raise quiz
def example_1
clean_env = false
t = Thread.new do
begin
ensure
clean_env = true
end
end
t.kill
t.join
@davidbegin
davidbegin / gist:c969f0554d60b7a026f5
Created October 6, 2015 21:50
Aggregating HTTP status Codes in a Pass Through
Nemo calls out to Panda and Nightingale:
What status should Nemo return when:
Scenario 1:
Panda returns a 200
Nightingale returns a 500
Scenario 2:
Panda returns a 404
@davidbegin
davidbegin / problem_3.exs
Created December 4, 2015 04:51
Euler Problem 3 in Elixir
# Problem 3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the composite 600851475143 ?
# This solution was taken and modified from https://github.com/JordiPolo/euler_on_elixir
defmodule Euler.Problem2 do
def solve do
class PartyParrot
class << self
def party!
post_to_slack do
"#{party_parrot_key} " * 100
end
end
private
@davidbegin
davidbegin / acrnm.sh
Created September 14, 2017 13:54
J16-GT_FW1718
curl https://acrnm.com/products/J16-GT_FW1718 | grep -o '<img[ ]*src="[^"]*"' | sed "s/<img src=\"/https:\/\/acrnm.com/" | sed "s/\"//" | xargs -L 1 catpix
@davidbegin
davidbegin / irc.py
Last active June 28, 2020 23:00
Simplest message to IRC bot
import socket
import os
channel = os.environ["CHANNEL"]
def _handshake(server):
# Get the value for this here: https://twitchapps.com/tmi/
token = os.environ["TWITCH_OAUTH_TOKEN"]
# Note the bot name will not be what is specifed here,
@davidbegin
davidbegin / measure_memory.py
Created January 21, 2020 03:43
Measure Memory usage of functions with a decorator
# Stolen from: https://medium.com/survata-engineering-blog/monitoring-memory-usage-of-a-running-python-program-49f027e3d1ba
print("\33c")
import tracemalloc
def measure_memory(func):
tracemalloc.start()
@davidbegin
davidbegin / looking_glass_quiz.py
Created January 23, 2020 17:42
Can you implement a context manager to make the test pass?
import pytest
# DON'T UPDATE THIS JUST CREATE A CONTEXT MANAGER
def reverso():
with YOUR_CONTEXT_MANAGER as what:
return print("Alice, Kitty and Snowdrop")
def test_looking_glass(capsys):
reverso()
@davidbegin
davidbegin / else_quiz.py
Created January 23, 2020 17:44
Take your best guess for 10 tests, to find out your Else Score
import pytest
def while_with_else_1():
x = True
while x:
print("It's been a while!")
x = False
else:
return "Goodbye my sweet love"
import pytest
from cool_code import *
def test_something():
assert True