Skip to content

Instantly share code, notes, and snippets.

View harley's full-sized avatar

Harley Trung harley

View GitHub Profile
@harley
harley / install-redis.sh
Last active September 11, 2021 21:18 — forked from phamk/install-redis.sh
Use latest stable
#!/bin/bash
###############################################
# To use:
# chmod +x install-redis.sh
# ./install-redis.sh
###############################################
version=stable
port=6379
@harley
harley / rake_benchmark.rb
Created July 14, 2012 22:36
Benchmarking a rake task
# Put this in Rakefile (doesn't matter where)
require 'benchmark'
class Rake::Task
def execute_with_benchmark(*args)
bm = Benchmark.measure { execute_without_benchmark(*args) }
puts " #{name} --> #{bm}"
end
alias_method :execute_without_benchmark, :execute
@harley
harley / activeadmin-cancan.rb
Created July 6, 2012 02:30
Deep integration of CanCan into ActiveAdmin
# blog post:
module ActiveAdmin
module ViewHelpers
# lib/active_admin/view_helpers/auto_link_helper.rb
def auto_link(resource, link_content = nil)
content = link_content || display_name(resource)
if can?(:read, resource) && registration = active_admin_resource_for(resource.class)
begin
@harley
harley / gist:b3d55b8b622b8fd7ba1c
Created July 29, 2015 07:18
remove merged branches on remote origin, handling feature/blah branches
git branch -r --merged | grep -vw "master" | grep -vw "HEAD" | grep -vw "develop" | cut -d "/" -f2 -f3| xargs -p -I {} git push origin :{}
@harley
harley / manual.rb
Last active September 26, 2017 19:26
compile js manually to detect unsupported syntax in asset js
# source https://stackoverflow.com/a/38605526
JS_PATH = "app/assets/javascripts/**/*.js";
Dir[JS_PATH].each do |file_name|
puts "\n#{file_name}"
puts Uglifier.compile(File.read(file_name))
end

Heading 1 – Normally A Document Titlte

Heading 2 – Section A

Heading 3 – Subsection A.1

This is a .docx document.

Bold Text

// sample code in the Swift class I'm teaching, on making network request to Instagram to get photos
var clientId = "Put your client id here"
// if you like to use Swift's Dictionary data type, you can use: `let photos = [Dictionary<String, AnyObject>]()`
let photos = [NSDictionary]()
var url = NSURL(string: "https://api.instagram.com/v1/media/popular?client_id=\(clientId)")!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url) { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
guard error == nil else {
@harley
harley / README.md
Last active February 20, 2017 09:17
Homework 2 README.md

Homework 2 - Name of App

Name of your app is a Ruby on Rails blog application that allows users to send messages to each other that can only be read once.

Submitted by: Your Name Here

Time spent: X hours

URL: Insert your Heroku URL here

@harley
harley / gist:3118186
Created July 15, 2012 19:07
remove old branches that have been merged
# adapted from http://devblog.springest.com/a-script-to-remove-old-git-branches
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
@harley
harley / vim sort ip addresses
Last active January 2, 2016 13:59
Sort by IP addresses in vim
# source: http://stackoverflow.com/questions/9067559/sorting-ip-addresses-in-vim
:%s/\<\d\d\?\>/0&/g|%&&|sor r/\(\d\{3}\)\%(\.\d\{3}\)\{3}/|%s/\<00\?\ze\d//g