Skip to content

Instantly share code, notes, and snippets.

@jchilders
jchilders / create_compilation.zsh
Created December 14, 2024 19:32
combine videos and add titles using ffmpeg
#!/bin/zsh
# Exit on error
set -e
# Enable null_glob option to handle no matches
setopt null_glob
# Function to handle errors
handle_error() {
@jchilders
jchilders / treesitter-build-install.zsh
Created November 11, 2021 20:03
Basic instructions on building tree-sitter from source
# How to build tree-sitter from source and get the Ruby parser to work with it.
mkdir -p $HOME/workspace/
cd $HOME/workspace/
# clone tree-sitter itself
git clone git@github.com:tree-sitter/tree-sitter.git
# clone the Ruby parser
git clone git@github.com:tree-sitter/tree-sitter-ruby.git
# Build & install the tree-sitter CLI
#!/usr/bin/env bash
#
# Show server's certificate in a human-readable form.
#
# Usage: $ show-cert HOST [PORT]
#
exec <&- # close stdin to suppress `read:errno=0` from openssl
exec openssl x509 -noout -text \
-in <(openssl s_client -connect "$1":"${2:-443}" -showcerts)
@jchilders
jchilders / check_cert.rb
Created August 23, 2019 13:58
Check SSL certs on your machine
#!/usr/bin/env ruby
if ARGV.include?("-h") || ARGV.include?("--help")
puts "USAGE: check_cert [HOSTNAME] [TLS_VERSION] [VERIFY]"
puts " default: check_cert rubygems.org auto VERIFY_PEER"
puts " example: check_cert github.com TLSv1_2 VERIFY_NONE"
exit 0
end
host = ARGV.shift || "rubygems.org"
@jchilders
jchilders / gpdr.rb
Created May 18, 2017 14:36
script to merge/rebase develop branch with the branch you are currently on
#!/usr/bin/ruby
require 'English'
`git diff-files --quiet`
unless $CHILD_STATUS.success?
puts 'You have uncommitted changes. Doing nothing'
exit(1)
end
@jchilders
jchilders / pre-commit
Last active February 17, 2016 15:34
pre-commit git hook to run karma, eslint, rspec before allowing the push. For rspec,
#!/bin/zsh
# This hook will cause a push to fail if any Jasmine (JavaScript) or rspec tests fail.
# If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
@jchilders
jchilders / pre-commit
Created December 4, 2015 16:17
git pre-commit hook to run rubocop against staged .rb files
#!/usr/bin/ruby
#
# Pre-commit hook that runs rubocop against all modified ruby files
require 'json'
rb_files = `git diff --name-only --staged`.split().reject{|f| !f.end_with?('.rb')}
exit(0) if rb_files.empty?
str = "rubocop -F -f json #{rb_files*" "}"
@jchilders
jchilders / ffjar
Created June 22, 2014 14:52
Quickly and recursively search through a directory's JAR files for a given text pattern
# Search all jar files in the current directory and below for the given string
# usage: ffjar <pattern>
# Requires GNU parallel and the_silver_searcher
function ffjar() {
jars=(./**/*.jar)
print "Searching ${#jars[*]} jars for '${*}'..."
parallel --no-notice --tag unzip -l ::: ${jars} | ag ${*} | awk '{print $1, ":", $5}'
}
@jchilders
jchilders / FunctionalJava.java
Created June 19, 2014 20:28
Java 8 Lambda Example
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.lang.System.out;
public class FunctionalJava {
@jchilders
jchilders / gist:3694841
Created September 10, 2012 23:40
Install the harbor gem and create a new app called 'ht'
#! /bin/bash
cd ~/workspace/harbor
rake build
cd ~/temp
gem install ~/workspace/harbor/pkg/harbor-1.0.gem
rm -r ht
harbor setup ht
cd ht
rackup