Skip to content

Instantly share code, notes, and snippets.

Hoàng Xuân Phú phunehehe

View GitHub Profile
@phunehehe
phunehehe / newconfig
Created Feb 25, 2011
In Gentoo, after updating you may see the message "IMPORTANT: <number> config files in '/etc' need updating.". This script looks for all the files that need to be updated, then overwrite old config files with new ones. Useful when there are a lot of new c
View newconfig
#! /bin/sh
# Update: There is no point using this, we have `etc-update'
for new_config in $(find /etc/ -name '._cfg????_*')
do
old_config=$(echo $new_config | sed 's:\([a-zA-Z0-9]*\)\._cfg[0-9]\{4\}_\([a-zA-Z0-9]*\):\1\2:')
if [[ -f "$new_config" || -f "$old_config" ]]
then
mv $new_config $old_config
else
@phunehehe
phunehehe / organize.sh
Created Aug 21, 2011
Organize files by file extension
View organize.sh
#!/bin/sh
# Organize files by file extension
# Written in answer to http://unix.stackexchange.com/q/19110/250
# Configuration (feel free to add your types and change the path)
DOCUMENTS='
pdf
doc
'
@phunehehe
phunehehe / solo.rb
Created Aug 28, 2012
solo.rb that knows where it is
View solo.rb
chef_dir = File.expand_path(File.dirname(__FILE__))
cookbook_path [
"#{chef_dir}/chef-cookbooks",
"#{chef_dir}/site-cookbooks",
]
role_path "#{chef_dir}/chef-repo/roles"
@phunehehe
phunehehe / stupid-spiders.md
Last active Dec 12, 2015
Block weird requests coming from stupid spiders
View stupid-spiders.md

Nginx

set $stupid_spider "";

# If the request comes from one of these stupid spiders
if ($http_user_agent ~* (stupid|spider)) {
    set $stupid_spider "1";
}
View sequence.py
WHATEVER_NUMBER_YOU_LIKE = 42
def sequence(input):
if input == 0:
return 340
if input == 1:
return 680
if input == 2:
return 1428
if input == 3:
@phunehehe
phunehehe / philesight-ubuntu.md
Last active Jan 25, 2016
Philesight on Ubuntu
View philesight-ubuntu.md

Install dependencies

sudo apt-get install libdb4.2-ruby1.8 libcairo-ruby1.8

Install Philesight

git clone https://github.com/phunehehe/philesight.git
View commands.md

Print permissions in a way that is suitable for executing again

for i in *
do
    echo chown $(stat -c%U:%G $i) $i
    echo chmod $(stat -c%a $i) $i
done
@phunehehe
phunehehe / ssh.md
Created Mar 15, 2013
Add self's SSH key to another account to gain access
View ssh.md

Add self's SSH key to another account to gain access

user=xyz
sudo mkdir -p /home/$user/.ssh
sudo cp -i ~/.ssh/authorized_keys /home/$user/.ssh/
sudo chown -R $user:$user /home/$user/.ssh
sudo chmod -R go-rwx /home/$user/.ssh
@phunehehe
phunehehe / mutt-ses.md
Last active Mar 7, 2018
Settings for Mutt to test SES
View mutt-ses.md

Change the email address to the verified sender address. By default Mutt doesn't use the envelope address, resulting in the email getting rejected because of unverified address.

set from = 'Amazing Tester <tester@amazing.com>'
set smtp_pass = 'xxx'
set smtp_url = 'smtps://xxx@email-smtp.xxx.amazonaws.com'
set use_envelope_from = yes
@phunehehe
phunehehe / git-cheatsheet.md
Last active Dec 15, 2015
Super condensed Git cheatsheet
View git-cheatsheet.md

Install Git

# Ubuntu
sudo apt-get install git
# OSX http://mac.github.com/

Create a Git repository in the current directory

# Open a terminal, `cd` to the project directory and then
git init
You can’t perform that action at this time.