Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env zsh
datadir=${XDG_DATA_HOME:-$HOME/.local/share}/windows
mkdir -m 0700 -p $datadir
git -C $datadir init
logfile=$datadir/windows-vms
exec >>$logfile
date=$(date)
echo
echo "# $date"
curl -fsSL https://developer.microsoft.com/en-us/microsoft-edge/api/tools/vms/ | \
@tarranjones
tarranjones / 0_reuse_code.js
Created December 12, 2016 11:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tarranjones
tarranjones / array_change_key_type.php
Created December 12, 2016 23:16
array key casting
<?php
function array_change_key_type(array $array, $type = T_STRING_CAST )
{
if($token === T_STRING_CAST) {
$obj = new stdClass();
foreach($array as $key => $value){
$obj->{$key} = $value;
}
return (array) $obj;
@tarranjones
tarranjones / archive_repo.sh
Created January 6, 2017 12:57
Archives a a git repository in $HOME/{hostname}/{username}/{repository} and optionally creates a symlink to the git directory
archive_repo(){
mkdir -p ~/$1
if ! git -C ~/$1 pull; then
git clone https://$1.git ~/$1
fi
if [ ! -z "$2" ]; then
mkdir -p $2
rm -rf $2
@tarranjones
tarranjones / require_gist.sh
Created January 6, 2017 21:43
How to require a Gist using Composer
add_gist_repository(){
composer config repositories.$1 '{"type":"package","package": {"name": "'$1'","version": "master","source": {"url": "https://gist.github.com/'$1'.git","type": "git","reference":"master"},"autoload": {"classmap": ["."]}}}'
}
require_gist(){
add_gist_repository $1
composer require $1:dev-master
}
@tarranjones
tarranjones / .extract.function
Last active February 1, 2017 23:03
# Extract archives - use: extract <file>
# Based on http://dotfiles.org/~pseup/.bashrc
function extract() {
if [ -f "$1" ] ; then
local filename=$(basename "$1")
local foldername="${filename%%.*}"
local fullpath=`perl -e 'use Cwd "abs_path";print abs_path(shift)' "$1"`
local didfolderexist=false
if [ -d "$foldername" ]; then
didfolderexist=true
@tarranjones
tarranjones / move_git_repo.sh
Created February 16, 2017 17:08
How to Move a Git Repo
mkdir -p ~/prestine/ #stores prestine git repos, no dev happens here (mostly just used for phpstorm framework intergartion)
move_repo(){
rm -fr ~/prestine/$2
git clone https://$1.git ~/prestine_repos/$2
cd ~/prestine_repos/$2
git remote set-url origin https://$2.git
git push origin master
cd -
@tarranjones
tarranjones / move_git_repo.sh
Created February 16, 2017 17:08
How to Move a Git Repo
mkdir -p ~/prestine/ #stores prestine git repos, no dev happens here (mostly just used for phpstorm framework intergartion)
move_repo(){
rm -fr ~/prestine/$2
git clone https://$1.git ~/prestine_repos/$2
cd ~/prestine_repos/$2
git remote set-url origin https://$2.git
git push origin master
cd -
@tarranjones
tarranjones / ssh_keygen.sh
Created March 2, 2017 09:24
ssh keygen stuff functions
# https://github.com/curtisalexander/til/blob/master/cl/ssh-config.md
# host="${1#*@}"
# user="${1%@*}"
function ssh_keygen(){
ssh-keygen -t rsa -b 4096 -N "" -C "$USER@$HOSTNAME to $1" -f ~/.ssh/"$1_id_rsa"
pub_key $1
}
function pub_key(){
<?php
function is_valid_regex($vat,$country){
// current regex function
return true;
}
function validate_vat($vat,$country){
if(is_valid_regex($vat,$country)) {