Skip to content

Instantly share code, notes, and snippets.

View allienx's full-sized avatar

Alex Lin allienx

  • California
View GitHub Profile
@allienx
allienx / cors.go
Created March 8, 2020 22:39
Go cors headers
func writeCors(w http.ResponseWriter, origin string) {
allowedOrigins := []string{
`http://localhost:1234`,
`https://mydomain(\-\w+)?\.now\.sh`,
}
for _, s := range allowedOrigins {
if match, _ := regexp.MatchString(s, origin); match {
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Access-Control-Allow-Methods", "GET")
@allienx
allienx / helpers.rb
Last active May 14, 2020 16:23
Ruby helpers.
### Taken from: https://dalibornasevic.com/posts/68-processing-large-csv-files-with-ruby
def print_memory_usage
memory_before = `ps -o rss= -p #{Process.pid}`.to_i
yield
memory_after = `ps -o rss= -p #{Process.pid}`.to_i
bytes_used = memory_after - memory_before
mb_used = (bytes_used / 1000.0).round(2)
puts "Memory: #{mb_used} MB"
@allienx
allienx / config.fish
Last active November 3, 2019 23:57
fish shell
#!/usr/bin/env fish
source ~/.asdf/asdf.fish
set normal (set_color normal)
set magenta (set_color magenta)
set yellow (set_color yellow)
set green (set_color green)
set red (set_color red)
set gray (set_color -o black)
@allienx
allienx / .prettierrc
Last active February 15, 2022 12:22
Prettier config and WebStorm file watchers.
{
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
@allienx
allienx / .bash_profile
Last active July 21, 2019 00:17
macOS .bash_profile
# use coreutils ls
# brew install coreutils
alias ls="gls -lh --color=auto --group-directories-first"
alias ll="ls -la"
alias la="ls -Ad .*"
alias l="ls -C"
# colorful bash prompt
export PS1="\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
@allienx
allienx / ruby.md
Last active April 12, 2018 23:39
Ruby installation with rbenv

Sources: rbenv, ruby-build

macOS

Install Xcode Command Line Tools

xcode-select --install
@allienx
allienx / script.py
Created February 13, 2017 22:18
Python script starter snippet.
from getopt import getopt, GetoptError
import sys
def main():
try:
opts, args = getopt(sys.argv[1:], 'h', 'help')
except GetoptError as err:
print(err)
@allienx
allienx / index.html
Last active February 11, 2017 18:21
allienx animation
<!DOCTYPE html>
<html>
<head>
<title>allienx</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="animation-container">
<div class="letter">a</div>
<div class="letter">l</div>
@allienx
allienx / _ubuntu.md
Last active April 12, 2018 23:40
Ubuntu box setup

Ubuntu Setup

# setup desktop files
sudo cp /usr/share/applications/gnome-terminal.desktop ~/.local/share/applications
sudo cp /usr/share/applications/unity-control-center.desktop ~/.local/share/applications
sudo chown alin:alin ~/.local/share/applications/*
# update with values provided in .desktop gist files

# update .bashrc with better ls aliases
@allienx
allienx / commands.md
Last active December 29, 2017 12:12
Random collection of command line things

bash

# recursive chmod for directories and files
find /path/to/directory \( -type d -exec chmod -R 755 {} \; \) -o \( -type f -exec chmod -R 644 {} \; \)

git

# list last time a file was changed