Skip to content

Instantly share code, notes, and snippets.

@SZanlongo
SZanlongo / pseudocode.tex
Created March 5, 2018 14:11
How to format a pseudocode algorithm From: https://tex.stackexchange.com/q/204592
\documentclass{article}
\usepackage{amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}
\begin{document}
\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\underline{function Euclid} $(a,b)$\;
@SZanlongo
SZanlongo / point_along_line_given_dist.py
Last active January 24, 2019 17:06
Find point along a line given distance from end
import math
from operator import add
def steer(start: tuple, goal: tuple, distance: float) -> tuple:
"""
Return a point in the direction of the goal, that is distance away from start
:param start: start location
:param goal: goal location
:param distance: distance away from start
@SZanlongo
SZanlongo / nested_dict.py
Last active January 24, 2019 17:04
Create nested dictionary
from collections import defaultdict
def nested_dict():
return defaultdict(nested_dict)
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{gull}
\caption{Close-up of a gull}
\label{fig:gull}
\end{figure}
Figure \ref{fig:gull} shows a photograph of a gull.
@SZanlongo
SZanlongo / change_win_wall.md
Created August 4, 2017 17:31
Change Windows Wallpaper Based on Time of Day

Use the task scheduler and create a VBscript to change the wallpaper. Create a script for each wallpaper you intend to use.

dim shell
Set shell = WScript.CreateObject("WScript.Shell")
wallpaper = "C:\path\to\wallpaper.jpg"
shell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper
shell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

Save the file as something.vbs and add it to the task scheduler, and voila! You got it all working.

In PowerShell, enter:

Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }
n = 3
l=[[] for i in range(n)]
@SZanlongo
SZanlongo / pickles_to_csv.py
Created June 24, 2017 23:25
Pickles to CSV
import csv
import os
import pickle
def pickles_to_csv():
with open('data_file.csv', 'w') as file:
for filename in os.listdir("."):
if filename.endswith(".pkl"):
data_pickle = pickle.load(open(filename, "rb"))
w = csv.writer(file)
@SZanlongo
SZanlongo / line_to_points.py
Last active December 17, 2017 18:51
n-Dimensional Line to Points (Bresenham Decomposition?)
#output a series of points that take you from the start point to the end point
#each list corresponds to each dimension of the line
def line_to_pts(start, end):
dims = [abs(i - j) for i, j in zip(start, end)]
max_dim = dims.index(max(dims))
max_diff = abs(end[max_dim] - start[max_dim])
points = []
for dim in range(len(start)):

Find a point along a line segment in three-dimensional space, given two points.

For example: Find a point along a line segment between point $a(-2, -2, -2)$ and $b(3, 3, 3)$ which is at distance $3$ from point $a$, in the direction of point $b$.

Begin by creating a vector $\mathbf{\overrightarrow{\text{BA}}}$ by subtracting $\mathbf{A}$ from $\mathbf{B}$: $\langle 3, 3, 3 \rangle - \langle -2, -2, -2 \rangle = \langle 5, 5, 5 \rangle$. Then, normalize this vector by dividing $\mathbf{\overrightarrow{\text{BA}}}$ by its length, $ \frac{\mathbf{\overrightarrow{\text{BA}}}}{\lVert \mathbf{\overrightarrow{\text{BA}}} \rVert} = \frac{\langle 5, 5, 5 \rangle}{\sqrt{5^2+5^2+5^2}} = \langle 0.577, 0.577, 0.577 \rangle$. This new unit vector can then be scaled and added to $\mathbf{A}$ to find the point in space at the desired distance. In this case: $\mathbf{A} + 3\langle 0.577, 0.577, 0.577 \rangle = \langle -0.268, -0.268, -0.268 \rangle$.