Skip to content

Instantly share code, notes, and snippets.

@ian-bartholomew
ian-bartholomew / gist:8922225
Created February 10, 2014 19:13
Git branch in bash prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
function proml {
local BLUE="\[\033[0;34m\]"
@ian-bartholomew
ian-bartholomew / es-percolate-test
Last active August 29, 2015 14:13
Elasticsearch percolate test
- create -
curl -XPUT 'localhost:9200/my-index/my-type/1' -d '{"title" : "Coffee percolator", "body" : "A coffee percolator is a type of ..."}'
- search -
curl -XGET 'localhost:9200/my-index/_search' -d '{"query" : {"match" : {"body" : "coffee"}}}'
- get all -
curl -XGET 'localhost:9200/my-index/_search?pretty=true'
- Register a query -
@ian-bartholomew
ian-bartholomew / crawl.rb
Last active October 2, 2015 20:19
site crawler ruby script with spidr https://github.com/postmodern/spidr
#!/usr/bin/env ruby
require 'rubygems'
require 'csv'
require 'spidr'
CSV.open('pets_crawl.csv', 'wb') do |csv|
csv << ['page title', 'page url']
Spidr.site('http://www.petsmart.com', :ignore_links => [/gsi/]) do |spider|
spider.every_html_page do |page|
function order(words){
// return empty string for undefined
if (words === undefined) {
return '';
}
let rval = [];
let pieces = words.split(' ');
for (let i=0; i<10; i++) {
if (pieces.hasOwnProperty(i)) {
@ian-bartholomew
ian-bartholomew / tmux-cheat-sheet.md
Last active April 7, 2019 20:19
Tmux Cheat Sheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Basic

start new:

 tmux

start new session with name:

@ian-bartholomew
ian-bartholomew / vim-cheat-sheet.md
Last active April 7, 2019 20:19
Vim cheat sheet

Vim cheat sheet

Movement / Range

Word

w next word 
b prev word 
W next WORD 
B prev WORD 

e end of word

@ian-bartholomew
ian-bartholomew / recursive-factorial.js
Last active March 1, 2017 06:45
Recursive factorial function
/*
A function that computes a factorial recursively.
A factorial is when you take a number n and multiply by each preceding integer until you hit one.
n * (n-1) * (n-2) ... * 3 * 2 * 1
Call the function factorial
factorial(1) = 1
factorial(2) = 2
factorial(3) = 6
@ian-bartholomew
ian-bartholomew / zap_cli_scan.sh
Last active January 18, 2022 19:48
script to run owasp zap cli
#!/bin/sh
DOCKER=`which docker`
IMAGE='owasp/zap2docker-weekly'
URL='https://www.example.com'
ZAP_API_PORT='8090'
# Start our container
CONTAINER_ID=`$DOCKER run -d \
-p $ZAP_API_PORT:$ZAP_API_PORT \
@ian-bartholomew
ian-bartholomew / main.tf
Last active August 26, 2019 19:08
Terraform Hello World
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
ingress {
from_port = "${var.server_port}"
to_port = "${var.server_port}"
@ian-bartholomew
ian-bartholomew / vimdiff.md
Created May 6, 2017 00:42 — forked from mattratleph/vimdiff.md
vimdiff cheat sheet

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)