Skip to content

Instantly share code, notes, and snippets.

View TrevorS's full-sized avatar

Trevor Strieber TrevorS

View GitHub Profile
@TrevorS
TrevorS / casesafe.sh
Created January 4, 2018 18:55 — forked from scottsb/casesafe.sh
Create and manage a case-sensitive disk-image on macOS (OS X).
#!/bin/bash
# ---------------------------------------------------------
# Customizable Settings
# ---------------------------------------------------------
MOUNT_POINT="${CASE_SAFE_MOUNT_POINT:-${HOME}/casesafe}"
VOLUME_PATH="${CASE_SAFE_VOLUME_PATH:-${HOME}/.casesafe.dmg.sparseimage}"
VOLUME_NAME="${CASE_SAFE_VOLUME_NAME:-casesafe}"
VOLUME_SIZE="${CASE_SAFE_VOLUME_SIZE:-60g}"
@TrevorS
TrevorS / angularjs_directive_attribute_explanation.md
Created August 9, 2016 23:28 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@TrevorS
TrevorS / json_map_builder.ex
Created January 18, 2016 01:56 — forked from rcdilorenzo/json_map_builder.ex
Convert a elixir json-decoded object to a map no matter how deep
defmodule JSONMapBuilder do
def to_map(list) when is_list(list) and length(list) > 0 do
case list |> List.first do
{_, _} ->
Enum.reduce(list, %{}, fn(tuple, acc) ->
{key, value} = tuple
Map.put(acc, binary_to_atom(key), to_map(value))
end)
_ ->
list
#!/usr/bin/env ruby
# encoding: utf-8
random = Random.new
code = ''
4.times { code << random.rand(1..6).to_s }
puts %q(
Can you guess the code?
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError 'record_list not an Array of Hashes' unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return if record_list.empty?
record_list.in_groups_of(1000, false).each do |record_group|
key_list, value_list = convert_record_list(record_group)
sql = "INSERT INTO #{self.table_name} (#{key_list.join(', ')}) VALUES #{value_list.map {|rec| "(#{rec.join(', ')})" }.join(' ,')}"
self.connection.insert_sql(sql)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username)
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
GHBU_PASSWD=${GHBU_PASSWD-"<CHANGE-ME>"} # the password for that account
GHBU_GITHOST=${GHBU_GITHOST-"github.com"} # the GitHub hostname (see comments)
GHBU_PRUNE_OLD=${GHBU_PRUNE_OLD-true} # when `true`, old backups will be deleted