Skip to content

Instantly share code, notes, and snippets.

View earlonrails's full-sized avatar

Kevin Krauss earlonrails

  • Disney Streaming
  • San Francisco
View GitHub Profile
@earlonrails
earlonrails / get_defaults.sh
Created October 24, 2013 00:28
get all applications defaults on mac osx and write them to a file. For use with defaults read and defaults write.
sudo echo "Thanks."
for domain in $(defaults domains | sed 's/,//g' )
do
echo "$domain $(defaults read $domain)" >> /tmp/apple_defaults.txt
done
@earlonrails
earlonrails / shortestPath.js
Last active November 26, 2023 09:34
shortest path and bfs in es6 javascript
#!/usr/bin/env node
// Question found here:
// https://stackoverflow.com/questions/32527026/shortest-path-in-javascript
// Based on the first accepted answer
"use strict"
const expect = require('expect.js')
class Graph {
constructor(props) {
this.neighbors = {}
@earlonrails
earlonrails / fizzbuzz.sh
Last active November 25, 2022 11:15
Fizz Buzz in bash! Hooray!
#!/bin/bash
x=1
while [ $x -le 100 ]
do
if [[ 0 -eq "($x%3) + ($x%5)" ]]
then
# Check if divide by 3 & 5 #
echo "fizz buzz"
elif [[ 0 -eq "($x%5)" ]]
then
@earlonrails
earlonrails / mockNeoism.go
Last active March 9, 2022 09:45
Mock neo4j/neoism connection in go for testing
package testhelpers
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"github.com/jmcvetta/neoism"
)
#!/usr/bin/env node
// https://www.geeksforgeeks.org/find-if-given-matrix-is-toeplitz-or-not/
class Toeplitz {
static check(matrix) {
for (var i = 1; i < matrix.length - 1; i++) {
let row = matrix[i]
let prevRow = matrix[i - 1]
for (var j = 1; j < row.length - 1; j++) {
@earlonrails
earlonrails / merged_branches.sh
Last active November 22, 2021 21:11
delete merged branches in git, if you want to.
merged_branches(){
local current_branch=$(git rev-parse --abbrev-ref HEAD)
for branch in $(git branch --merged | cut -c3-)
do
echo "Branch $branch is already merged into $current_branch."
echo "Would you like to delete it? [Y]es/[N]o "
read REPLY
if [[ $REPLY =~ ^[Yy] ]]; then
git branch -d $branch
fi
@earlonrails
earlonrails / escapeShell.js
Last active September 16, 2021 12:31
escape strings to use for shell commands in javascript. Adapted from ruby shellwords. http://www.ruby-doc.org/stdlib-1.9.3/libdoc/shellwords/rdoc/Shellwords.html
// Adapted from ruby shellwords
var escapeShell = function(str) {
// An empty argument will be skipped, so return empty quotes.
if (str === "" || str === null) return "''"
var command = str;
// Treat multibyte characters as is. It is caller's responsibility
// to encode the string in the right encoding for the shell
// environment.
command = command.replace(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\$1")
#!/usr/bin/env ruby
Node = Struct.new(:value, :left, :right)
def create_tree(nodes, root=nil, idx=0)
if nodes.size > idx
root = Node.new(nodes[idx])
root.left = create_tree(nodes, root.left, 2 * idx + 1)
root.right = create_tree(nodes, root.right, 2 * idx + 2)
end
@earlonrails
earlonrails / application.xml
Created November 3, 2011 22:10
Simple adobe air browser.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<!-- Adobe AIR Application Descriptor File Template.
Specifies parameters for identifying, installing, and launching AIR applications.
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
The last segment of the namespace specifies the version
of the AIR runtime required for this application to run.
@earlonrails
earlonrails / splat.rb
Last active February 19, 2020 02:00
Iterm function which will create multiple tabs in a grid or vertical panes and execute the command or commands passed to it. ie. splat "ping google.com" "ping cnn.com" "ping twitter.com" "ping yahoo.com"
#!/usr/local/bin/ruby
require 'shellwords'
args = ARGV
size = args.size
tab_open = 'tell i term application "System Events" to keystroke "t" using {command down}'
v_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down}'
h_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down, shift down}'
go_left_one_pane = 'tell i term application "System Events" to key code 123 using {command down, option down}'
script_builder = Proc.new do |tell, command|