Skip to content

Instantly share code, notes, and snippets.

@sunapi386
sunapi386 / recover.md
Created February 7, 2018 19:58
How to recover locked out AWS EC2 ssh machine

One time I accidentally messed with the /etc/passwd and locked myself out of being able to SSH into the machine. Since this is a remote machine in AWS I had no way of doing what I'd normally do. Which is attaching a keyboard and monitor and fixing this manually.

To fix, use the AWS EC2 Management page to:

  • spin up a new instance of vanilla ubuntu EC2 (let's call it David)
  • shutdown the locked machine (let's call it Goliath)
  • unmount Goliath's volume
  • attach the volume to David

Then follow this guide: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

@sunapi386
sunapi386 / record_screen.sh
Created February 3, 2018 05:57
Record screen
#!/bin/bash
record_screen() {
SCREEN_RES=$(xrandr -q --current | grep '*' | awk '{print$1}')
DATE=$(date '+%Y-%m-%d-%H:%M:%S')
echo "saving to recording_$DATE.mkv"
echo "Ctrl-C to exit"
ffmpeg -loglevel panic -f x11grab -s $SCREEN_RES -i :0.0 -r 25 -vcodec libx264 "recording_$DATE.mkv"
}
record_screen
@sunapi386
sunapi386 / SimpleRasbian.sh
Last active June 23, 2018 22:39
Clean minimal Raspbian
#!/usr/bin/env bash
# Given a fresh install of a Raspian OS, install the necessary tools.
# This is only meant to run once to setup a brand new fresh OS install.
#
# Author: Jason Sun
# Date: Feb 01, 2018
#
packages(){
sudo apt update
@sunapi386
sunapi386 / register_monitor.py
Last active January 24, 2018 07:21
Sets a windows registry `key` in `path` every `duration` seconds to `value`.
# Jason Sun sunapi386@gmail.com
# Jan 22, 2018.
# Sets a registry `key` in `path` every `duration` seconds to `value`.
# E.g. Add/update a registry DWORD entry, set NC_ShowSharedAccessUI = 1
# Can be compiled to exe with:
# pyinstaller --onefile register_moniter.py
# See reference https://pythonhosted.org/PyInstaller/usage.html
from time import sleep
import winreg
import ctypes
@sunapi386
sunapi386 / x11vnc-start
Created January 15, 2018 23:56 — forked from tavinus/x11vnc-start
Starts VNC server for the current session
#!/bin/bash
###########################################################################
# /usr/local/bin/x11vnc-start
# Starts VNC server for the current session
#
# Gustavo Neves - 4th Jul 2016
#
# Install x11vnc:
# sudo apt-get install x11vnc

FWIW: I didn't produce the content present here. I've just copy-pasted it from somewhere over the Internet, but I cannot remember exactly the original source. I was also not able to find the author's name, so I cannot give him/her the proper credit.


Effective Engineer - Notes

What's an Effective Engineer?

@sunapi386
sunapi386 / PP15S-1.68.txt
Last active April 13, 2017 19:48
cambrionix
>> help
mode <m> [p] Set mode <m> for port [p] or all ports
mode c p f Set charge mode for port p using profile f if attached
state [p] Show state for port [p] or all ports
system Show hardware and firmware information
health Show voltages, temperature, error & boot flag
cef Clear error flags
sef <flag> Set error flag. One of: 5UV 5OV 12UV 12OV OT
crf Clear rebooted flag
limits Show voltage & temperature limits
@sunapi386
sunapi386 / coins.py
Created February 22, 2017 03:41
Dynamic Programming: Taking Coins
# DP practice problem.
# Feb 21, 2017.
# Jason Sun sunapi386.ca
#
# Problem
#
# You are a given collection of coins, where each stack of coins is of h height, and there are s stacks.
# Take exactly h coins, such that the sum of the coins is the maximum possible.
# Caveat: if you take a coin from a stack, all the coins above it must be taken too.
#
@sunapi386
sunapi386 / comments.sh
Created February 9, 2017 03:08
train stats
bash-3.2$ find . \( -iname "*.h" -o -iname "*.c" \) -exec /bin/echo {} + | xargs awk -f lc.awk
--------------------------------File---Code---Comments---Raw Lines
-------------- ./include/kernel/scheduler.h 68 11 93
./user/sensor.c 154 25 190
./track/new/track_data_new.c 2352 1 2357
./include/user/clock_drawer.h 4 0 6
./include/utils.h 36 0 46
./include/user/parser.h 5 0 6