Skip to content

Instantly share code, notes, and snippets.

@mcrumm
mcrumm / phx_sqlite_fly_launch.md
Last active May 3, 2024 09:38
Phoenix + SQLite Deployment tips

Deploying to Fly.io with SQLite

Deploying a Phoenix app to Fly.io is a breeze...is what everyone kept telling me. In fairness, I imagine the process would have been breezier had I just used postgres, but all the sqlite and litestream talk has been far too intriguing to ignore. "Wait", you say. "It is just a flat file. How much harder can it be?"

It is easy to make something harder than it should be. It is hard to take something complex and make it truly simple. flyctl launch does an amazing job at providing a simple interface to the utterly complex task of generating deployment resources, especially now that we are living in a containerd (erm, firecracker) world.

This gist is for anyone who, like me, thinks they know better than to read all of the documentation and therefore necessari

@MineRobber9000
MineRobber9000 / README.md
Created July 7, 2020 03:29
Import Python modules from GitHub

githubimport

Allows you to import Python modules from the top level of a GitHub repository. Basically, golang's import semantics but in Python fashion.

>>> import githubimport
>>> from MineRobber9000.test_modules import blah
>>> blah.foo()
"bar"
@justinvanwinkle
justinvanwinkle / broken.py
Last active March 22, 2024 22:52
Every python rate-limiting library (that I can find) is broken, at least a little.
# I was looking for a rate limiting library to call rate limited apis as closely
# as possible to their enforced limits. I looked at the first few python libraries
# that I found, and when I glanced at the source, they were all clearly broken.
# Curious how this could be, I took all the top google and pip search results for: python rate limiting
# and tried to get them to do the wrong thing and fail to rate limit in situations that could come up
# in normal use (though in some cases very specific use)
# https://github.com/tomasbasham/ratelimit
# Where broken:
@magnetikonline
magnetikonline / README.md
Last active March 21, 2024 00:11
Add user ssh-agent as daemon to Ubuntu 18.04LTS server.

Add user ssh-agent as daemon to Ubuntu 18.04LTS server

Create a new systemd user unit, which starts ssh-agent upon login to server. Will remain resident until the final session for the user has logged out.

Steps

  • Create /etc/systemd/user/ssh-agent.service.

  • Run the following commands (under your user account, not root) to install the systemd unit and start:

@gene1wood
gene1wood / role_arn_to_session.py
Created December 29, 2016 17:38
Simple python function to assume an AWS IAM Role from a role ARN and return a boto3 session object
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""
@robertberry-zz
robertberry-zz / countPermutations.js
Created September 4, 2016 18:38
O(n) algorithm for counting permutations of a string in another string
function countChars(word) {
var counts = {};
for (var i = 0; i < word.length; i++) {
var letter = word[i];
if (letter in counts && counts.hasOwnProperty(letter)) {
counts[letter]++;
} else {
counts[letter] = 1;
@kenoir
kenoir / gist:bed1a6ee7749137959fe2d372edeba86
Created March 31, 2016 15:17
AWS CLI Infra list incantations
aws cloudformation list-stacks | jq ".StackSummaries[].StackId" -r | grep "PROD"
aws ec2 describe-instances --filters Name=tag:Stage,Values=PROD | jq ".Reservations[].Instances[].InstanceId" -r
aws elb describe-load-balancers | jq ".LoadBalancerDescriptions[].LoadBalancerName" -r
aws autoscaling describe-auto-scaling-groups | jq ".AutoScalingGroups[].AutoScalingGroupName" -r | grep "PROD"
aws s3 ls | grep "prod" | awk '{print $3}'
aws ec2 describe-vpcs | jq ".Vpcs[].VpcId" -r
aws dynamodb list-tables | jq ".TableNames[]" -r | grep "PROD"
aws sqs list-queues | jq ".QueueUrls[]" -r | grep "PROD"
aws sns list-topics | jq ".Topics[].TopicArn" -r | grep "PROD"
@macournoyer
macournoyer / Output
Last active January 9, 2023 15:12
A Neural Network framework in 25 LOC
$ python xor.py
Training:
Epoch 0 MSE: 1.765
Epoch 100 MSE: 0.015
Epoch 200 MSE: 0.005
* Target MSE reached *
Evaluating:
1 XOR 0 = 1 ( 0.904) Error: 0.096
0 XOR 1 = 1 ( 0.908) Error: 0.092
1 XOR 1 = 0 (-0.008) Error: 0.008
@roylines
roylines / remote-terraform-s3-policy
Created September 19, 2015 10:46
IAM policy to allow storing of remote terraform state in S3
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::my.bucket",
@treeder
treeder / README.md
Last active April 27, 2018 20:34
Serving static site on app engine with golang

Put all your static files in /static directory. If you put index.html into /static, it will be served up as welcome file.