Skip to content

Instantly share code, notes, and snippets.

View myles's full-sized avatar
🦖

Myles Braithwaite myles

🦖
View GitHub Profile
@myles
myles / momentjs_format.py
Created September 18, 2024 16:11
Moment.js like formatter for Python.
"""
This module provides utilities for working with Moment.js date formats in
Python.
"""
import datetime
import re
from typing import Union
@myles
myles / dataclasses_utils.py
Created August 27, 2024 20:54
Function to merges two dataclass instances
from dataclasses import asdict, is_dataclass
def merge_dataclasses(dataclass_a, dataclass_b):
"""
Merge two dataclasses into a new dataclass.
"""
if (
is_dataclass(dataclass_a) is False
and is_dataclass(dataclass_b) is False
@myles
myles / README.md
Last active December 13, 2023 22:52
Backwards port of Django 5.0's update_or_create function

Backwards port of Django's 5.0 update_or_create

The update_or_create model function was updated in Django 5.0 with a create_defaults argument that allows only used during create operations.

@myles
myles / README.md
Last active September 15, 2023 23:02
Colly & Go vs. BeautifulSoup & Python

Colly & Go vs. BeautifulSoup & Python

> time go run cryptocoinmarketcap.go
2017/12/19 17:26:38 Scraping finished, check file "cryptocoinmarketcap-go.csv" for results
        2.24 real         0.84 user         0.45 sys

> time python3 cryptocoinmarketcap.py
WARNING:root:Scraping finished, check file cryptocoinmarketcap-py.csv for results
 3.51 real 2.94 user 0.07 sys
@myles
myles / csv_spliter.py
Last active August 14, 2017 15:31
Quick Python script for splitting large CSV files using Pandas and NumPy.
#!/usr/bin/env python3
import argparse
import math
import os.path
import pandas as pd
import numpy as np
def main(filepath):
@myles
myles / fabfile.py
Created July 11, 2017 19:25
Fabric File for deploying a Laravel website
import datetime
from fabric.api import cd, env, task, run
from fabric.contrib.project import rsync_project
from fabric.utils import puts
env.hosts = ['127.0.0.1']
env.user = 'serverpilot'
env.app_dir = '~/apps/laravel/'
env.releases_dir = '~/.releases/laravel'
@myles
myles / fabfile.py
Created June 27, 2017 13:21
Trellis Fabric File for Transferring Production to Staging
import datetime
import yaml
from ansible_vault.api import Vault
from fabric.api import env, execute, get, local, put, run, task
env.user = 'root'
env.now = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
env.roledefs = {
@myles
myles / happy_valentines_day.py
Last active February 14, 2017 15:47
happy_valentines_day.py
#!/usr/bin/env python3
import argparse
def encode(secret):
binary = bin(int.from_bytes(secret.encode(), 'big'))
return binary[2:].replace('0', '❤️').replace('1', '💜')
def decode(code):
@myles
myles / App.js
Created January 26, 2017 16:41
Playing around with WordPress REST API and React
import WordPress from 'wpcom';
import { css } from 'glamor'
import React from 'react';
let PostStyle = css({
borderBottomColor: '#ccc',
borderBottomStyle: 'solid',
borderBottomWidth: '1px',
margin: '1em 0',
<html>
<head><title>Fuzzy Search</title>
<script id="algorithm">
// YOUR CODE HERE !
</script>