Skip to content

Instantly share code, notes, and snippets.

View MatrixManAtYrService's full-sized avatar

Matt Rixman MatrixManAtYrService

View GitHub Profile
@MatrixManAtYrService
MatrixManAtYrService / fstring.py
Last active January 5, 2020 21:24
Python 3.6 f-strings
adult_price = 120
child_price = 60
total_tickets_purchased = 3
adult_ticket = 3
child_ticket = 0
availble_seats = 150
adult_cost=adult_price*adult_ticket
child_cost=child_price*child_ticket
total_cost=adult_cost+child_cost
total_tickets_purchased=(adult_ticket+child_ticket)
@MatrixManAtYrService
MatrixManAtYrService / Dockerfile
Last active January 3, 2023 00:52
Run a script as a specific service account on google AI platform
FROM centos:centos7
RUN yum install -y python3 wget
# GCloud Access
RUN wget -nv \
https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz && \
mkdir /root/tools && \
tar xvzf google-cloud-sdk.tar.gz -C /root/tools && \
rm google-cloud-sdk.tar.gz && \
/root/tools/google-cloud-sdk/install.sh --usage-reporting=false \
@MatrixManAtYrService
MatrixManAtYrService / bash output
Last active February 13, 2023 03:32
zsh vs bash, two redirection strategies
NONSWAPPED_OUT
nonswapped_err
tee out: NONSWAPPED_OUT
tee err: nonswapped_err
swapped_err
SWAPPED_OUT
tee out: SWAPPED_OUT
tee err: swapped_err
docker info
Containers: 21
Running: 0
Paused: 0
Stopped: 21
Images: 47
Server Version: 18.09.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
import json
print(json.dumps({"JSON1" : "Hello World!",
"JSON2" : "Hello my World!",
"JSON3" : {"key1" : "value1"}))
@MatrixManAtYrService
MatrixManAtYrService / user_lookup
Created May 13, 2019 18:17
parse_bot_commands
for event in slack_events:
if event['type'] == 'message':
mentiond_id, message = parse_direct_mention(event['text'])
# is it for me?
if mentiond_id == self_id:
# classify recipient
from_user = 'subtype' not in event
@MatrixManAtYrService
MatrixManAtYrService / ModuleNotFound
Created May 8, 2019 15:34
Maybe they changed the API?
❯ docker run --rm -it ubuntu:18.04
# apt update && apt install -y python3-pip python3-venv
... output omitted ..
# python3 -m venv ~/venv
# source ~/venv/bin/activate
(venv) # python -c 'import slackclient'
Traceback (most recent call last):
@MatrixManAtYrService
MatrixManAtYrService / go
Last active May 6, 2019 02:51
bash parallelism example
#! /usr/bin/env bash
bg_process()
{
sleep 1
for i in a b c d e f g h i j k l m n o p
do
echo $i
sleep 1
done
}
@MatrixManAtYrService
MatrixManAtYrService / locustfile.py
Created February 6, 2019 18:47
example of keeping tasks on a single class
from locust import HttpLocust, TaskSet, task
import json
class UserBehavior(TaskSet):
def on_start(self):
# this retrieves a coookie from the server and stores in in a RequestsCookieJar: self.locust.client.cookes
# that is, it stores the cookie on an instance of this class, not the class itself (as your code does)
# your server may have different requirements for how the login request should look, but this worked for me
self.client.post("/login",
@MatrixManAtYrService
MatrixManAtYrService / luigi
Created January 18, 2019 18:54
Linux pipe reconstruction
#! /usr/bin/env bash
# This script interrogates the system and constructs a JSON representation of the pipeline that it is part of.
# It is a proof-of-concept. A more useful utility would accept a parameter that targets not the pipeline of the
# utility itself, but insted that of its parent, or grandparent, or great grandparent, or whatever. Such a tool could
# be used to sense the correct output-format based on who is listening downstream.
# Usage Example:
# cat -b | ./luigi | cat -e | jq .