Skip to content

Instantly share code, notes, and snippets.

@dciccale
dciccale / .bashrc
Created February 9, 2022 18:58
bash alias to open a pull request on github
pr() {
local _open=$(if [[ `uname -s` == "Linux" ]]; then echo "xdg-open"; else echo "open"; fi)
local repo=`git config --get remote.origin.url | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
local branch=`git rev-parse --abbrev-ref HEAD`
$_open https://github.com/$repo/pull/new/$branch
}
@dciccale
dciccale / http-ping.sh
Created July 27, 2016 07:22
Print http status every `n` seconds
# Print http status every n seconds
# n defaults to 1s
# usage:
# http-ping google.com .5 (500 milliseconds)
# http-ping google.com 2 (2 seconds)
http-ping() {
n=1 && (($#>1)) && n=$2
while true
do
curl -o /dev/null --silent --head --write-out '%{http_code}\n' $1
@dciccale
dciccale / docker-enter
Last active March 30, 2022 16:48
docker-enter bash alias to enter a docker container
# usage docker-enter [CONTAINER_ID]
dockerenter() {
docker exec -it $1 bash
}
alias docker-enter=dockerenter
@dciccale
dciccale / demo.html
Created June 4, 2014 11:10
Client-side template engine
<!doctype html>
<script>function t(s,d){for(var k in d)s=s.replace(new RegExp('{{\\s*'+k+'\\s*}}','g'),d[k]);return s;}</script>
<script type="template" id="tmpl">
<h1>Hello {{ name }}!</h1>
</script>
<script>
var tmpl = document.getElementById('tmpl').innerHTML;
@dciccale
dciccale / README.md
Last active December 22, 2015 03:49
Binary search function done with 109 bytes of JavaScript

binarySearch

Tiny binary search done with 109 bytes of JavaScript.

@dciccale
dciccale / README.md
Last active May 22, 2018 09:14
Cross-browser triggerEvent function done with 127 bytes of JavaScript

triggerEvent

Cross-browser function to trigger DOM events.

@dciccale
dciccale / git_branch.sh
Created May 11, 2013 18:02
Bash script to get the current git branch and last commit
#!/usr/bin/env bash
# checks if branch has something pending
function parse_git_dirty() {
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*"
}
# gets the current git branch
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
@dciccale
dciccale / README.md
Last active March 27, 2016 18:19
Cross-browser eventHandler function done with 270 bytes of JavaScript

eventHandler

Cross-browser function to handle DOM events.

@dciccale
dciccale / README.md
Last active December 17, 2015 00:29
Cross-browser removeEvent function done with 84 bytes of JavaScript

removeEvent

Cross-browser function to remove events from DOM elements.

@dciccale
dciccale / README.md
Last active December 16, 2015 06:49
Cross-browser addEvent function done with 81 bytes of JavaScript

addEvent

Cross-browser function to add events on DOM elements.