Skip to content

Instantly share code, notes, and snippets.

@masasin
masasin / fix_times.py
Last active March 9, 2024 13:41
Google Photos uses `datetime_original` EXIF tag to sort photos. If using a physical camera etc, the times can be wrong. Fix them by running this with the `exif` library on PyPI.
import datetime as dt
from pathlib import Path
from typing import NoReturn
from exif import Image
TIMEDELTA = -dt.timedelta(hours=8, minutes=12, seconds=10)
DATE_FORMAT = "%Y:%m:%d %H:%M:%S" # Verify
filtered_freq = [f if (950 < index < 1050 and f > 1) else 0 for index, f in enumerate(freq)]
@masasin
masasin / AB_salary_calculator.py
Last active August 9, 2016 13:45
Salary calculator for Alberta - Hourly wage to yearly net
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Convert an hourly wage to weekly, monthly, and (gross and net) yearly incomes.
Assumes that work is being done in Alberta, Canada.
"""
from __future__ import division, print_function
import argparse
@masasin
masasin / traffic_light_simulation.py
Last active November 28, 2015 09:26
Code cleanup for /u/SquidgeyBear. (See thread at http://redd.it/3tpv6v, and comment at https://goo.gl/G2H67c)
#!/usr/bin/env python3
"""
Runs a simulation of a traffic light cycle.
Written by /u/masasin as code cleanup for /u/SquidgeyBear. See the original
thread at https://redd.it/3tpv6v, and the explanatory comments at
https://goo.gl/G2H67c.
"""
from itertools import cycle
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Automate merging of git branches
# Copyright © 2015 Jean Nassar
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Get a list of network interfaces on Linux
# Copyright © 2015 Jean Nassar
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
@masasin
masasin / Niko Nico Ordering Process
Last active August 29, 2015 14:18
Niko Nico Ordering Process
// customer cancels
/receive cancel request/;
cancel_order:
cancel order;
return;
// customer orders
/receive order/;
if urgent {
@masasin
masasin / yozakura local_client.py
Created April 3, 2015 09:24
Client code to test yozakura's server
import pickle
import socket
import time
# Create a socket (SOCK_STREAM means a TCP socket)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect to server and send data
sock.connect(("localhost", 9999))
@masasin
masasin / calculate_aldrin_periods_ksp.py
Created February 12, 2015 19:46
Calculate Kerbin-Duna Aldrin cycler periods in KSP
def calculate_periods(precision=1e-1, periods_to_check=1000, print_first_n=7):
"""Calculate optimal orbital periods for a Kerbin-Duna cycler.
This assumes that the cyclers will have the same orbital period as the
synodic period. Multiples of this period are also acceptable, but the
results will need to be modified accordingly.
All arguments are optional.
Args: