Skip to content

Instantly share code, notes, and snippets.

@anhkind
anhkind / gist:45447fa8347e491c3a0a
Created December 12, 2015 10:19 — forked from nicdev/gist:7282303
Some nmap scans I need to keep notes for
# Discover live hosts on a subnet
# nmap -sP -PE -PP -n [subnet in CIDR notation]
nmap -sP -PE -PP -n 192.168.1.0/24
# Scan for installed software and versions
# nmap -sV --version-all [CIDR or IP]
nmap -sV --version-all 192.168.1.0/24
@anhkind
anhkind / color_util.rb
Created May 30, 2015 07:31
Use SASS functions to lighten/ darken a (hex) color Rails
class ColorUtil
class << self
def lighten hex_color, percent
adjust :lightness, hex_color, percent
end
def darken hex_color, percent
adjust :lightness, hex_color, percent * -1
end
@anhkind
anhkind / active_admin.rb
Created May 21, 2015 13:04
Monkey patching to ActiveAdmin (v0.6.0) to have multiple column sorting (config.sort_order = "column1_desc, column2_asc")
# initializers/active_admin.rb
module ActiveAdmin
class ResourceController
module DataAccess
# monkey patch to have multiple column sorting as "column1_asc, column2_desc"
def apply_sorting(chain)
params[:order] ||= active_admin_config.sort_order
orders = []
params[:order].present? && params[:order].split(/\s*,\s*/).each do |fragment|
@anhkind
anhkind / date_stub.js
Last active August 29, 2015 14:18
Stub JS Date
var lastNow = new Date();
var lastStubbedNow = new Date(1421224206 * 1000);
var oldDate = Date;
// stub with new Date function
Date = function () {
var args = arguments.length > 0 ? Array.prototype.slice.call(arguments) : [getStubbedNow().getTime()];
args.unshift(null)
return new ( Function.prototype.bind.apply( oldDate, args ) ) // http://stackoverflow.com/a/8843181/1036829
@anhkind
anhkind / heroku_postgres.sh
Last active August 16, 2022 11:16
Heroku postgres: dump and restore
# Details: https://devcenter.heroku.com/articles/heroku-postgres-import-export
# Create postgres role (v13) if not existing yet
createuser -s postgres -U <os-username>
# Dump
heroku pg:backups capture
curl -o latest.dump `heroku pg:backups public-url`
# Restore to local db
@anhkind
anhkind / bookmarklet
Last active August 29, 2015 14:07
Inject JS file
javascript:(function(){ var file = prompt("Paste URL of the js file here:"); document.body.appendChild(document.createElement('script')).src=file;})()
@anhkind
anhkind / gist:fcbd6bcddbf28abaa211
Created July 25, 2014 13:53
Run ngrok to background
ngrok -log=stdout 80 > ngrok.log &
" copy all this into a vim buffer, save it, then...
" source the file by typing :so %
" Now the vim buffer acts like a specialized application for mastering vim
" There are two queues, Study and Known. Depending how confident you feel
" about the item you are currently learning, you can move it down several
" positions, all the way to the end of the Study queue, or to the Known
" queue.
" type ,, (that's comma comma)
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@anhkind
anhkind / pre-commit
Last active December 22, 2015 06:49
Git pre-commit hook with rspec
#!/usr/bin/env ruby
exit 0 if ENV["SKIP_TEST"] # set environment SKIP_TEST to skip rspec
require 'pty'
html_path = "/tmp/rspec_results.html"
begin
puts "Running rspec ..."
PTY.spawn( "rspec spec --format h > /tmp/rspec_results.html" ) do |stdin, stdout, pid|
begin
stdin.each { |line| print line }
rescue Errno::EIO