Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# SPDX-License-Identifier: MIT
## Copyright (C) 2009 Przemyslaw Pawelczyk <przemoc@gmail.com>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Lockable script boilerplate
@adamvduke
adamvduke / quick_post.rb
Created August 12, 2011 02:44
curl is great unless you have a bunch of form params to post
require 'restclient'
#flip verbose to get more or less output
verbose = true
if verbose
require 'net-http-spy'
Net::HTTP.http_logger_options = {:verbose => true}
end
# params get form-encoded
@r2k0
r2k0 / sed_snippets.sh
Last active September 30, 2024 11:05
sed examples
##FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
@kien
kien / gist:1610859
Created January 14, 2012 09:49
Custom statusline example
" File: after/plugin/ctrlp.vim
" Description: Custom statusline example
" Make sure ctrlp is installed and loaded
if !exists('g:loaded_ctrlp') || ( exists('g:loaded_ctrlp') && !g:loaded_ctrlp )
fini
en
" ctrlp only looks for this
@rymawby
rymawby / compare_lines.rb
Created January 20, 2012 15:34
Ruby script to compare two text files - analysed what lines exist in file1 that do not in file2.
#!/usr/bin/ruby
# script to compare and see what lines are in file1 but not file2
f1 = File.open('file1.txt')
f2 = File.open('file2.txt')
file1lines = f1.readlines
file2lines = f2.readlines
@dgolds
dgolds / dgSniffCode.sh
Last active October 11, 2015 18:37
Bash Script to do quick counts of common source code types under the current or specified directory
#!/bin/bash
# Bash Script to do quick counts of common source code types under the current or specified directory
# https://gist.github.com/3901863
# To quickly grab it, just type
# wget https://gist.github.com/raw/3901863/dgSniffCode.sh && chmod +x dgSniffCode.sh
# Features to add:
# multiple params ...A hack until I support * arguments: ls | xargs -L 1 ~/dgSniffCode
@ccstone
ccstone / BBEdit-TextWrangler_RegEx_Cheat_Sheet.txt
Last active October 26, 2024 06:05
BBEdit-TextWrangler Regular Expression Cheat-Sheet
————————————————————————————————————————————————————————————————————————————————————————————————————
BBEdit / BBEdit-Lite / TextWrangler Regular Expression Guide Modified: 2018/08/10 01:19
————————————————————————————————————————————————————————————————————————————————————————————————————
NOTES:
The PCRE engine (Perl Compatible Regular Expressions) is what BBEdit and TextWrangler use.
Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete.
@aaronsaunders
aaronsaunders / nix-cheat.sh
Last active January 25, 2021 06:54
Quick reference for nix command line commands that I can never remember...
# Unix shell
# run if zero exit
cd tmp/a/b/c && tar xvf ~/archive.tar # untar if dir exists
# run if non-zero exit
cd tmp/a/b/c || mkdir -p tmp/a/b/c
cd tmp/a/b/c || mkdir -p tmp/a/b/c && tar xvf -C tmp/a/b/c ~/archive.tar
which
whereis
@pkuczynski
pkuczynski / parse_yaml.sh
Last active September 23, 2024 01:42
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@stevenrombauts
stevenrombauts / progressbar.sh
Created February 26, 2014 14:37
Bash Progress Bar
#!/bin/bash
# Slick Progress Bar
# Created by: Ian Brown (ijbrown@hotmail.com)
# Please share with me your modifications
# Note: From http://stackoverflow.com/questions/11592583/bash-progress-bar
# Functions
PUT(){ echo -en "\033[${1};${2}H";}
DRAW(){ echo -en "\033%";echo -en "\033(0";}
WRITE(){ echo -en "\033(B";}
HIDECURSOR(){ echo -en "\033[?25l";}