Skip to content

Instantly share code, notes, and snippets.

View cander's full-sized avatar

Charles Anderson cander

View GitHub Profile
@cander
cander / make-dir-hierarchy.rb
Last active March 6, 2019 01:17
Create a hierarchy of files and directories based on the output of find
#!/bin/env ruby
#
# Given output from find(1) listing files and directories, reproduce that
# hierarchy with random data in the files.
#
# Usage: ruby make-dir-hierarchy.rb [find-output-file]
#
require 'securerandom'
@cander
cander / slow-rm.sh
Last active March 1, 2019 23:12
Slowly remove file files in a directory
#!/bin/bash
#
# Slowly remove files from a directory
# Usage: slow-rm.sh [-dry-run] dir
#
# Removes files older than MIN_AGE_DAYS one at a time syncing and
# sleeping after every BATCH_SIZE files.
# A BATCH_SIZE of 300 will take at least 56 minutes to remove 1M files
BATCH_SIZE=300
@cander
cander / vim-cheat-sheet.md
Last active December 7, 2022 22:55
A personal cheat sheet for vim

Vim Cheat Sheet

FYI - this is not a general-purpose cheat sheet for vim. I've been using vim/vim for over 35 years.
So, this is more of list of random things in core-vim or various plugin-ins that I've recently started using or am strugging to remember when I need them.

Tags

Use exerberant ctags for best results. (It's not the default ctags program on MacOS.)

g-] Search for the tag under the cursor and select between multiple possible matches.

@cander
cander / httpstest.java
Last active May 23, 2018 23:16
A simple test program to fetch HTTPS URLs that have been problematic with older versions of Java
import java.net.URL;
import java.io.InputStream;
public class httpstest {
public static void fetchUrl(String urlStr, String msg)
{
try {
System.out.println(msg);
System.out.println("Opening " + urlStr);
URL url=new URL(urlStr);
@cander
cander / docker-cheat-sheet.md
Created August 8, 2017 21:19
Docker Cheat Sheet

Docker Cheat Sheet

All of these assume you're running as root. If not, preface them with sudo as needed.

List of Dangling Images

docker images --filter 'dangling=true' 

To remove them:

docker images -q --filter 'dangling=true' | xargs docker rmi
@cander
cander / elastic-search-api-imports.md
Last active April 12, 2016 21:43
Some information missing from the ElasticSearch Java client documentation - e.g., what imports are needed and a pointer to some JavaDocs.

Git Cheat Sheet

This isn't intended as an exhaustive reference for git. Rather, it's a collection of operations that I perform so rarely that I always have to look up how to do them.

Fetch Just One Remote Branch

(because I have a weak-ass Internet connection at home)

git fetch --no-tags <remote> <remote-branch-name>:<local-branch-name>

Abandon a Merge

git reset --hard HEAD

@cander
cander / gist:e22a84605d8c4a501a67
Created October 11, 2014 23:05
Vagrant file for Modern IE boxes
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrant file for Modern IE (https://www.modern.ie/en-us) boxes
# This file is for Windown 7 running IE9, but there are other possibilities.
# NB: Vagrant wants to ssh into the VM, but these VMs don't have ssh. So,
# you'll get a timeout error message, which is safe to ignore.
# To use a different box, replace the config.vm.box_url with the URL and
# update the config.vm.box to some name you want to refer to it as.
@cander
cander / gist:5267753
Last active February 12, 2016 11:27
How to write to the Google Plus moments.insert API endpoint from Ruby.
# This Sinatra endpoint is something I added to the Google Ruby quick-start
# web app - https://developers.google.com/+/quickstart/ruby
# It demonstrates how to write to the moments.insert API, for which I
# couldn't find any Ruby examples.
post '/write_activity' do
# Check for stored credentials in the current user's session.
if !session[:token]
halt 401, 'User not connected.'
end
@cander
cander / basic.sh
Created May 25, 2012 04:47
Bourne Basic - a BASIC interpreter implemented (painfully) in pure Bourne shell
#!/bin/sh
#
#
# From: [email protected] ([email protected])
# Subject: bournebasic
# Newsgroups: comp.sources.misc
# Date: 1987-08-18 18:54:12 PST
#
# Here's a useful BASIC interpreter written in Bourne shell.
# There's no manual but this demo shows the most salient features: