Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Landau brianjlandau

View GitHub Profile
@brianjlandau
brianjlandau / top_brews.sh
Last active Nov 10, 2019
Get the top 500 homebrew formula and browse
View top_brews.sh
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
View keybase.md

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 Mar 29, 2018
Rails 5.1 webpacker config for react + jest + enzyme
View .babelrc
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
View check-gzip
#!/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 Mar 25, 2016
This can be used so that when building records via nested attributes the correct subclass is used when creating the record.
View sti_nested_attributes_association_builder.rb
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)
View shared_history.sh
# History control
HISTFILESIZE=100000
export HISTFILESIZE
HISTSIZE=100000
export HISTSIZE
HISTCONTROL=ignoredups:erasedups
export HISTCONTROL
shopt -s histappend
_bash_history_sync() {
View uri_validator.rb
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 Aug 26, 2015
One way to get a list of authors who worked on a specific directory and how many commits they contributed.
View gist:51395f332a93358fab10
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 Aug 25, 2015
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.
View share_on_change.js
/**
* 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 = {
View array_of_matcher.rb
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
You can’t perform that action at this time.