Skip to content

Instantly share code, notes, and snippets.

@mawaldne
mawaldne / gist:8697866
Created January 29, 2014 21:46
Non greedy regex
Finds:
routing_number\": \"01030800\"
account_number\": \"02010101\"
Grep with perl:
grep -Poh 'routing_number\\".*?\\".*?\\"' file.txt
grep -Poh 'account_number\\".*?\\".*?\\"' file.txt
@mawaldne
mawaldne / gist:e32823b130c9e98af606
Created September 21, 2014 21:48
Serve some htmls locally to anyone
# Install node http-server
sudo npm install http-server -g
# Install ngrok - https://ngrok.com/
brew install ngrok
# Change to the directory you want to serve:
@mawaldne
mawaldne / gist:34d7dd9977b9fbe65473
Created January 2, 2015 00:06
[2014-12-28] Challenge #195 [Easy] Symbolic Link Resolution
# run as: ruby sym_link_reso.rb input.txt
lines = open(ARGV[0]).readlines
directory = lines.last
symlinks = lines[1..-2].each_with_object({}) do |line, hash|
symlink = line.chomp.split(':')
hash[symlink[0].chomp("/")] = symlink[1].chomp("/")
end
@mawaldne
mawaldne / yank_to_system_register.vim
Last active December 5, 2015 18:56
Vim - Automatically yank to system clipboard from Visual mode
Yank normally, but just copy it automatically to your system clipboard as well.
Added to my .vimrc. Should work from visual mode when you press y and from ex mode: 1,10YankToSystemRegister
" Auto Yank text to the OS X clipboard
function! CopyToSystemRegister()
let @*=@"
endfunction
command! -range -bar YankToSystemRegister <line1>,<line2>yank|call CopyToSystemRegister()
vnoremap y :YankToSystemRegister<cr>
@mawaldne
mawaldne / gist:6275270
Last active December 21, 2015 07:59
Utility method to update semantic version number. Useful when tagging a new version.
def updateBuildVersion(currentVersion, updateType) {
def versionMatcher = currentVersion =~ /^(\d+)\.(\d+)\.(\d+)$/
def major = versionMatcher[0][1].toInteger()
def minor = versionMatcher[0][2].toInteger()
def patch = versionMatcher[0][3].toInteger()
if (updateType == 'patch')
patch += 1
else if (updateType == 'minor')
minor += 1
@mawaldne
mawaldne / gist:7831963
Created December 6, 2013 20:56
Kramdown test
require 'kramdown'
puts Kramdown::Document.new(File.open('test.md').read).to_html
@mawaldne
mawaldne / gist:7832688
Last active December 30, 2015 12:59
Time methods using closures in groovy
def timeMethod(method, message) {
def startTime = System.currentTimeMillis()
method()
def totalTime = System.currentTimeMillis() - startTime
log.info "${message} ${totalTime} ms"
}
...
timeMethod({ someMethod() }, "someMethod Time:")
...
Fiction:
On Writing (Stephen King)
Masters of Doom
Hackers: Heroes of the computing revolution
Sci fi:
Ready Player One
Cryptonomicon
Old Mans War
@mawaldne
mawaldne / gist:ed33840e9a6d55918ad2d7631159f450
Created August 17, 2016 15:00
Audible Books as of Aug 17, 2016
The Phoenix Project
Meditations
Ego Is the Enemy
Smarter Faster Better
Flash Boys: A Wall Street Revolt
@mawaldne
mawaldne / TokenAuthentication.scala
Last active January 22, 2020 19:37
Token Authentication example for Scalatra
package yourpackage
import org.scalatra.auth.strategy.BasicAuthSupport
import org.scalatra.auth.{ScentryConfig, ScentryStrategy, ScentrySupport}
import org.scalatra.{ScalatraBase, Unauthorized}
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import java.util.Locale
class TokenAuthRequest(r: HttpServletRequest) {