Skip to content

Instantly share code, notes, and snippets.

@noahlt
noahlt / code.sh
Created October 22, 2011 19:40
How do I make ack search through Mustache and ERB templates?
--type-set=mustache=.mustache
--type-set=rb=.rb
--type-set=erb=.erb
@noahlt
noahlt / code.sh
Created October 23, 2011 07:19
How do I kill whatever process is listening to a particular port?
function killport {
if [ $1 == '-h' ] || [ -z $1 ]; then
echo '`killport <PORT>` finds the process listening to the specified port and kills it.'
else
process_line=`sudo lsof -i :$1 | tail -1`
if [ "$process_line" == "" ]; then
echo "no processes listening on $1"
else
process_name=`echo "$process_line" | awk '{print $1}'`
echo "killing $process_name"
@noahlt
noahlt / code.sh
Created October 23, 2011 07:24
How can I quickly switch to the topmost directory in a git project?
function rcd {
prevdir=`pwd`
until ls -ld .git 1>/dev/null 2>/dev/null
do
cd ..
if [ `pwd` == '/' ]
then
cd $prevdir
return
@noahlt
noahlt / code.el
Created October 23, 2011 07:26
How do I make emacs' backward-kill-word not kill across line breaks?
(defun noah-backward-kill ()
"Exactly like backward-kill-word, except doesn't kill across line breaks."
(interactive)
(let ((init-pos (point))
(line-begin (line-beginning-position))
(word-begin (backward-word-position)))
(if (= (point) line-begin)
(backward-delete-char 1)
(if (< word-begin line-begin)
(kill-region line-begin init-pos)
@noahlt
noahlt / summary.md
Created October 23, 2011 07:30
Why does Apple think my email address has been already verified with another Apple ID?

Probably because it already has. In my case, I was trying to verify my email address (noah@gmail.com) with my Apple ID noahlt. Little did I know that I had already created a separate Apple ID noah@gmail.com, which was of course automatically bound to noah@gmail.com.

To solve this problem, I signed in to iTunes using noah@gmail.com and ignored my old noahlt Apple ID.

@noahlt
noahlt / summary.md
Created October 23, 2011 07:32
How do I pass a class in Scala?

In Java:

public class Foo { }

Foo.class

In Scala:

class Foo { }
@noahlt
noahlt / summary.md
Created October 23, 2011 21:35
How do I extract a particular column from text (like the output of ps)?

awk has a command for this:

$ awk '{print $2}' <filename>

You can, of course, also pipe in text output from another program:

$ who
noah     console  Oct 21 14:06 
noah     ttys000  Oct 23 13:08 

noah ttys001 Oct 23 14:00

@noahlt
noahlt / hi.html
Created April 22, 2012 18:25
why doesn't `body *:hover` work?
<html>
<head>
<style>
body * { background-color: #FCF0AD; }
body *:hover { background-color: blue; }
*:hover { background-color: blue; }
body li:hover { background-color: red; }
</style>
<body>
@noahlt
noahlt / killport.sh
Last active September 15, 2017 16:25
killport - kill whatever process is running on a given port
# add this to your .bash_profile to use it
# source: https://gist.github.com/noahlt/2662634
function killport {
if [ ! -n "$1" ] || [ $1 == '--help' ] || [ $1 == '-h' ]
then
echo '`killport <PORT>` finds the process listening to the specified port and kills it.'
else
process_line=`sudo lsof -i :$1 | tail -1`
if [ "$process_line" == "" ]
then
<html>
<!--
Copyright (c) 2013 Noah Tye <noah@tyes.us>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell