Skip to content

Instantly share code, notes, and snippets.

@danhyun
danhyun / apache parser
Created January 25, 2013 22:37
get hourly breakdown of requests to apache
grep "25/Jan" access_log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c
@danhyun
danhyun / gist:4660312
Created January 28, 2013 23:35
split sql batch file into 500 line pages with prefix
csplit -k some_file.sql -f some_file_prefix -b %02u.sql 500 {10000}
500 is number of lines
{10000} is how many times to repeat an action
@danhyun
danhyun / breakdown page-loads by day
Created January 31, 2013 19:24
Someone asked me to get a count per day breakdown of page loads for a particular page
$ grep "GET /foo/bar.html" access_log | awk '{print $4}' | cut -d: -f1 | uniq -c
281 [27/Jan/2013
288 [28/Jan/2013
40 [29/Jan/2013
38 [30/Jan/2013
20 [31/Jan/2013
$ grep "POST /foo/doBar.html" access_log | awk '{print $4}' | cut -d: -f1 | uniq -c
160 [27/Jan/2013
150 [28/Jan/2013
@danhyun
danhyun / ssh config
Last active December 14, 2015 00:09
set up ssh config
[root][henry][~]
$ cd ~/.ssh
[root][henry][~/.ssh]
$ ll -tr config
-rw-r--r-- 1 root root 143 2012-10-04 13:06 config
# note the permissions -> user:group [644]
[root][henry][~/.ssh]
$ cat config
@danhyun
danhyun / .bash_rc
Last active December 15, 2015 20:58
nice PS1
export PS1="[\[\033[1;31m\]\u\[\033[m\]][\[\033[32m\]\H\[\033[m\]][\[\033[36m\]\w\[\033[m\]]\n\$ "
@danhyun
danhyun / index.html
Created November 13, 2013 14:07
MTA Fare Calculator as of 2013 March Fare Hike
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MTA Fare Calculator</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="header">
@danhyun
danhyun / index.html
Created November 23, 2013 21:45
MTA Fare Calculator as of March 2013 fare hike
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MTA Fare Calculator</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="header">
@danhyun
danhyun / api in 19 lines.groovy
Last active August 29, 2015 13:57
fast and easy restclient
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
def apiUrl = 'http://localhost:8888'
def api = new RESTClient(apiUrl, ContentType.JSON)
api.headers = ['auth-key': '11', 'Accept': 'application/json; q=0.9,*/*; q=0.8']
def id = 20784
@danhyun
danhyun / html_fragment_validator.groovy
Last active August 29, 2015 14:03
A groovy service that validates HTML fragments
// For use with your own local copy of nu validator @ http://about.validator.nu/#src
@GrabConfig(systemClassLoader=true)
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import groovyx.net.http.HTTPBuilder
def client = new HTTPBuilder('http://localhost:8888')
def boundary = '----hyunlabs_boundary'
@danhyun
danhyun / BaseUrlHandler.groovy
Created August 20, 2014 14:06
Setting base url
class BaseUrlHandler implements Handler {
void handle(Context context) throws Exception {
context.with {
def headers = request.headers
def scheme = headers.contains('X-Forwarded-Proto') ? headers.get('X-Forwarded-Proto') : 'http'
def domain = headers.get('Host') ?: headers.get('host')
def baseUrl = "${scheme}://${domain}" as String