Skip to content

Instantly share code, notes, and snippets.

@t0mmyt
t0mmyt / wm
Created July 7, 2015 13:21
Gnome settings
# Resize with right click
gsettings set org.gnome.desktop.wm.preferences resize-with-right-button true
# Sloppy focus
gsettings set org.gnome.desktop.wm.preferences focus-mode sloppy
@t0mmyt
t0mmyt / xauth.txt
Created August 10, 2015 18:06
Copy Xauth between users
user1$ xauth list | grep unix`echo $DISPLAY | cut -c10-12` > /tmp/xauth
user2$ xauth add `cat /tmp/xauth`
@t0mmyt
t0mmyt / user_threads.sh
Created August 14, 2015 10:14
Monitoring
#!/bin/bash
# Count threads in use for a given user
die() {
echo $1
exit 1
}
[[ $# -eq 1 ]] || die "Need user as arg"
id $1 >/dev/null 2>&1 || die "User ($1) not found"
@t0mmyt
t0mmyt / no_tmout.sh
Created September 2, 2015 15:48
Remove read-only TMOUT in bash
#!/bin/bash
gdb --pid $PPID <<EOF
call unbind_variable("TMOUT")
detach
EOF
@t0mmyt
t0mmyt / LVM_cache.txt
Created November 17, 2015 16:16
LVM cache
[root@localhost ~]# lvcreate -L 10G -n root_cache fedora /dev/sdb2
Logical volume "root_cache" created.
[root@localhost ~]# lvcreate -L 20M -n root_cache_meta fedora /dev/sdb2
Logical volume "root_cache_meta" created.
[root@localhost ~]# man lvconvert
[root@localhost ~]# lvconvert --type cache-pool --cachemode writeback --poolmetadata fedora/root_cache_meta fedora/root_cache
WARNING: Converting logical volume fedora/root_cache and fedora/root_cache_meta to pool's data and metadata volumes.
THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
Do you really want to convert fedora/root_cache and fedora/root_cache_meta? [y/n]: y
Converted fedora/root_cache to cache pool.
@t0mmyt
t0mmyt / .profile
Last active January 2, 2016 20:52
Hadoop user profile
dfs()
{
hdfs dfs "$@" 2>&1 | grep -v 'using builtin-java classes where applicable'
}
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export HADOOP_INSTALL=~/hadoop
export HADOOP_HOME=$HADOOP_INSTALL
export PATH=$PATH:$HADOOP_INSTALL/bin:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
@t0mmyt
t0mmyt / verbose.scala
Last active November 6, 2017 16:56
Scala Code Smells
val this_instruction = "sml." + fields(1).capitalize + "Instruction"
val instruction_args = fields.drop(2)
val c_int = classOf[Int]
val c_str = classOf[String]
val instruction = instruction_args.length match {
case 1 =>
val c = Class.forName(this_instruction).getConstructor(c_str, c_str, c_int)
c.newInstance(fields(0), fields(1), fields(2).toInt: Integer).asInstanceOf[Instruction]
case 2 =>
val c = Class.forName(this_instruction).getConstructor(c_str, c_str, c_int, c_int)
@t0mmyt
t0mmyt / build.sh
Last active October 10, 2016 15:50
Building ruby 2.2 with rbenv (on Arch)
RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.so" curl -fsSL https://gist.github.com/mislav/055441129184a1512bb5.txt | rbenv install --patch 2.2.0
@t0mmyt
t0mmyt / Get my ASG
Last active April 21, 2016 15:20
AWS CLI
# Requires describe tags in IAM
aws ec2 --region eu-west-1 describe-tags --filter "Name=resource-id,Values=$(curl -ss http://169.254.169.254/latest/meta-data/instance-id)" | jq '.Tags[] | select(.Key=="aws:autoscaling:groupName").Value'
# Get IPs of other instances in my ASG
aws ec2 --region eu-west-1 describe-instances --filter Name=tag:aws:autoscaling:groupName,Values=$(aws ec2 --region eu-west-1 describe-tags --filter "Name=resource-id,Values=$(curl -ss http://169.254.169.254/latest/meta-data/instance-id)" | jq '.Tags[] | select(.Key=="aws:autoscaling:groupName").Value') | jq '.Reservations[].Instances[] | select(.State.Name=="running") | .NetworkInterfaces[0].PrivateIpAddress'
function addIfNotIn {
grep "${1}" ${2} >/dev/null 2>&1 || echo "${1}" | tee -a ${2}
}