Skip to content

Instantly share code, notes, and snippets.

@jia3857
jia3857 / .screenrc
Created June 19, 2021 05:38 — forked from bcomnes/.screenrc
ssh agent forwarding in tmux and gnu screen
# Fix agent forwarding
# https://gist.github.com/martijnvermaat/8070533
# http://techblog.appnexus.com/2011/managing-ssh-sockets-in-gnu-screen/
# See .ssh/rc for socket linking
unsetenv SSH_AUTH_SOCK
setenv SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock.$HOSTNAME
@jia3857
jia3857 / 1-macOS-10.14-mojave-setup.md
Created May 17, 2021 02:07 — forked from kevinelliott/1-macOS-10.14-mojave-setup.md
macOS 10.14 Mojave Mostly-Automated Setup

To support my open-source work, consider adding me on Patreon.

macOS 10.14 Mojave Mostly-Automated Setup

An easy to refer to document for regularly setting up macOS 10.14 Mojave.

Controversy

The topic of recipe-based frequent fresh reinstalls of macOS is a controversial issue. Some people are against reinstalling macOS, citing that they have never had an issue with Apple provided upgrade installs.

## Setup `dnsmasq` and configure for *.test domains
$ brew install dnsmasq
$ vim /usr/local/etc/dnsmasq.conf
## EDIT $(brew --prefix)/etc/dnsmasq.conf
# setup domain(s) responsible by dnsmasq
echo 'address=/.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
#!/usr/bin/env bash
# Setup ~/.dotfiles.git
git clone --bare https://github.com/jia3857/dotfiles3.git $HOME/.dotfiles.git
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'
# function dotfiles() {
# /usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'
# }
# export -f dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'
@jia3857
jia3857 / [Facebook]lca.cpp
Created July 26, 2020 09:48 — forked from skxie/[Facebook]lca.cpp
find lowest common ancestor with parent pointer. #fb #lca #tree #binarytree O(1) space and O(n) time.
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode *parent;
TreeNode(int x) : val(x), left(NULL), right(NULL), parent(NULL) {}
};
int getHeight(TreeNode *node) {
int height = 0;
@jia3857
jia3857 / osx_setup.md
Created June 25, 2020 18:01 — forked from millermedeiros/osx_setup.md
Mac OS X setup

Setup Mac OS X

I've done the same process every couple years since 2013 (Mountain Lion, Mavericks, High Sierra, Catalina) and I updated the Gist each time I've done it.

I kinda regret for not using something like Boxen (or anything similar) to automate the process, but TBH I only actually needed to these steps once every couple years...

# Installing VirtualBox on CentOS 7.
# Install dependencies
yum -y install gcc make patch dkms qt libgomp perl
yum -y install kernel-headers-$(uname -r) kernel-devel-$(uname -r) fontforge binutils glibc-headers glibc-devel
# Install VirtualBox 6.1
cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
yum install VirtualBox-6.1
# Some notes from installing VirtualBox on CentOS 7.
# These exact steps haven't been tested, as I ran them in a different order when manually installing.
# Install dependencies
yum -y install gcc make patch dkms qt libgomp
yum -y install kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel
# Install VirtualBox
cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
@jia3857
jia3857 / duplicates.py
Created March 13, 2020 02:32 — forked from tfeldmann/duplicates.py
Fast duplicate file finder written in python
#!/usr/bin/env python
"""
Fast duplicate file finder.
Usage: duplicates.py <folder> [<folder>...]
Based on https://stackoverflow.com/a/36113168/300783
Modified for Python3 with some small code improvements.
"""
import os
import sys
# Write a function isvalid() to take start_state, ['_','L','R','_'], finish_state ['L','_','_','R'] strings
# so that return True if start_state can transition to finish_state
class Solution:
def isvalid(self, start, finish):
sStart = self.state_transition(start)
sFinish = self.state_transition(finish)
print " sStart = {} ==> {}".format(start, ''.join(sStart))
print "sFinish = {} ==> {}".format(finish, ''.join(sFinish))