Skip to content

Instantly share code, notes, and snippets.

@Nateowami
Nateowami / README.md
Last active May 6, 2023 14:59
Auto-Sync with Unison
Summery

This is a simple script for syncing Unison profiles. Basically, given a list of profiles (which must already be created in Unison), it will sync all files with non-conflicting states. It logs the time of start and completion to unison.log (change OUTPUT=$HOME/unison.log if you want it to output somewhere else), as well as listing the output Unison gives for each sync. Unison already knows the hosts to sync, because that's recorded by Unison in the profiles it stores in ~/.unison. And you'll need SSH keys already setup.

Automating

If you want to automate this script in Ubuntu, search the dash for "Startup Applications" and open it up, then click on "add" in the window that opens. You'll be prompted for a name and command. Name it anything you like and make the command the path to the script, e.g. `~/scr

@Nateowami
Nateowami / pin.js
Created June 15, 2015 06:08
PIN Generator
// Released into the public domain
// Set this to the number of digits you want in your PIN
var pinDigits = 4;
var pin = "";
function random(){
return Math.floor(Math.random()*10);
}
@Nateowami
Nateowami / video-dimensions.js
Last active November 7, 2018 22:43
JS function to calculate the active are of an HTML5 video (i.e. the are of the element that is showing the video).
function videoDimensions(video) {
// Ratio of the video's intrisic dimensions
var videoRatio = video.videoWidth / video.videoHeight;
// The width and height of the video element
var width = video.offsetWidth, height = video.offsetHeight;
// The ratio of the element's width to its height
var elementRatio = width/height;
// If the video element is short and wide
if(elementRatio > videoRatio) width = height * videoRatio;
// It must be tall and thin, or exactly equal to the original ratio
@Nateowami
Nateowami / README.md
Last active December 28, 2016 08:46
Rename According to Image or Video Metadata

Bash one-liners to rename images or videos according to metadata (date or dimensions)

Pictures

jhead -nIMG_%Y%m%d_%H%M%S *.jpg

Short and simple, jhead takes a format string after the -n CLI flag. It only works with JPEGs though. On Ubuntu 16.04, install the jhead package.

Videos

@Nateowami
Nateowami / README.md
Last active January 24, 2017 06:40
HTML5 boilerplate

Recommended (by me) HTML5 starter code

HTML doesn't actually require all of these tags, but it's good practice to include them, in my opinion. The following actually passes the W3C validator:

<!DOCTYPE html><title>T</title>

Feel free to suggest improvements. I'm thinking there may be some meta tags that should be added (e.g. a viewport one--something about mobile devices--can't remember).

@Nateowami
Nateowami / divide_by_tiny_numbers.js
Created February 14, 2017 09:15
JavaScript tiny number divided by zero
``` javascript
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001/0
Infinity
```
``` javascript
> 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001/0
NaN
```
@Nateowami
Nateowami / README.md
Created March 1, 2017 14:34
Failed username login attempts

See what usernames bots try to log into your server with

zgrep searches in zipped and unzipped files.

List unique usernames used in failed login attempts:

sudo zgrep -ohP "input_userauth_request: invalid user \K\w+" /var/log/auth.log* | sort -u
@Nateowami
Nateowami / README.md
Created May 19, 2017 07:45
Using appcache

Application Cache notes

Major important things to remember when working with the app cache

https://html.spec.whatwg.org/#manifests

This feature is in the process of being removed from the Web platform. (This is a long process that takes many years.) Using any of the offline Web application features at this time is highly discouraged. Use service workers instead. [SW]


Contrary to one source, it appears the spec still requires the text/cache-manifest mime-type. Older browsers do as well, and its unclear which ones, so we should probably use it for the sake of the many devices running the older Android browsers.

@Nateowami
Nateowami / README.md
Last active December 18, 2017 05:12
Audio file

Just an audio file for testing.

@Nateowami
Nateowami / ubuntu1604installer.sh
Created May 23, 2018 21:09
Modified xForge installer script
#!/bin/bash
set -eux
# add mongo's public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
if [ `whoami` == "root" ]
then
echo This script cannot be run as sudo!