Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
View GitHub Profile
@brianjlandau
brianjlandau / top_brews.sh
Last active November 10, 2019 02:58
Get the top 500 homebrew formula and browse
curl "https://formulae.brew.sh/api/analytics/install-on-request/homebrew-core/90d.json" | \
jq ".formulae |
to_entries |
sort_by([(.value[].count | gsub(\",\"; \"\") | tonumber)] | add) |
reverse |
map({key: .key, value: ([(.value[].count | gsub(\",\"; \"\") | tonumber)] | add)})[0:500] |
from_entries" | \
less

Keybase proof

I hereby claim:

  • I am brianjlandau on github.
  • I am brianjlandau (https://keybase.io/brianjlandau) on keybase.
  • I have a public key ASADZdepX0J5-Vj2nmxaby26kkElaVpSHeHAW6n6Hg3j_Qo

To claim this, I am signing this object:

@brianjlandau
brianjlandau / .babelrc
Last active March 29, 2018 07:41
Rails 5.1 webpacker config for react + jest + enzyme
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
#!/usr/bin/env bash
if [ ${#1} -eq 0 ]
then echo "Error: Please supply a URL"; exit 1;
fi
ENCODING_HEADER=$(curl --silent -I $1 -H "Accept-Encoding: gzip,deflate" | tr -d '\r' | sed -En 's/^Content-Encoding: (.+)$/\1/p')
if [ "$ENCODING_HEADER" == "gzip" ]
then echo "GZIP: Enabled"
@brianjlandau
brianjlandau / sti_nested_attributes_association_builder.rb
Created March 25, 2016 18:19
This can be used so that when building records via nested attributes the correct subclass is used when creating the record.
ActiveRecord::Reflection::AbstractReflection.class_eval do
def build_association(*options, &block)
attributes = if options.first.is_a?(Hash)
options.first.with_indifferent_access
end
if attributes && attributes[:type].present?
attributes[:type].constantize.new(*options, &block)
else
klass.new(*options, &block)
# History control
HISTFILESIZE=100000
export HISTFILESIZE
HISTSIZE=100000
export HISTSIZE
HISTCONTROL=ignoredups:erasedups
export HISTCONTROL
shopt -s histappend
_bash_history_sync() {
require 'uri'
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.present?
begin
unless URI(value).is_a?(URI::HTTP)
record.errors.add(attribute, :invalid_uri, options)
end
rescue
@brianjlandau
brianjlandau / gist:51395f332a93358fab10
Created August 26, 2015 23:18
One way to get a list of authors who worked on a specific directory and how many commits they contributed.
git log --pretty=%an your/path | awk -F, '{++freq[$1];}END{for (author in freq)printf "%s\t%d\n", author, freq[author];}'
@brianjlandau
brianjlandau / share_on_change.js
Created August 25, 2015 22:20
Allows you to abstract out the common behaviour of wanting to create an onChange function that just sets the Colonel Kurtz value based on the input value.
/**
* SharedOnChange Colonel Kurtz Mixin
* Allows you to abstract out the common behaviour of wanting to
* create an onChange function that just sets the CK value
* based on the input value.
*/
var React = require('react')
module.exports = {
RSpec::Matchers.define :be_an_array_of do |expected|
match do |actual|
actual.is_a?(Array) && actual.all?{|item| item.is_a?(expected) }
end
failure_message do |actual|
"expected that #{actual} would be an array #{expected}"
end
end