Skip to content

Instantly share code, notes, and snippets.

View brandondrew's full-sized avatar

Brandon Zylstra brandondrew

  • UC Berkeley
  • the tubes
View GitHub Profile
@mletterle
mletterle / gist:8048086
Last active November 26, 2021 08:56
Replay Two Git Repositories History Into A New One, Chronologically

Combining Two (or more potentially) Git Repos

###Moving one repo into a subdirectory of the other

Preserves notes and sets commit details to author details

in newrepo

@stoft
stoft / orient_connector.ex
Last active December 10, 2015 15:48
Basic OrientDB HTTP/REST backend to Phoenix web framework
defmodule Phtest.OrientConnector do
use Jazz
@base_url "http://localhost:2480/"
@database "Phtest"
@user "admin"
@password "admin"
@basic_auth [basic_auth: {@user, @password}]
def get(document_id, type) do
OrientConnector.get_document(document_id)
@jhass
jhass / .rubocop.yml
Last active December 15, 2023 22:23
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
from scapy.all import *
def arp_display(pkt):
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
print "ARP Probe from: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)
@CrCs2O4
CrCs2O4 / gems_homepages.rb
Last active June 4, 2018 19:04
Get ruby gems homepages fo fast googling. Sometimes 'gem list' is not enough
#!/usr/bin/env ruby
# bundler exec ruby gems_homepages.rb
# based on http://stackoverflow.com/questions/5177634/list-of-installed-gems
require 'rubygems'
def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end
puts local_gems.map{ |name, specs|
@mankind
mankind / rails-jsonb-queries
Last active May 23, 2024 06:47
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@huobazi
huobazi / deploy.rb
Created February 21, 2019 02:32 — forked from Epigene/deploy.rb
Mina deployment file for rails applications
# Mina Deploy
# ===========
#
# Adapted from Creative deploy stack in Manabalss v4, Mar.2015, updated to support staging on Jun.2015
# On first deploy do: mina setup --verbose
# Then do : mina deploy[initialize] --trace
#
# Usage examples:
# mina deploy[soft,seed,compile] to=staging # deploy task with all options | a simple `mina deploy` will deploy to production
# mina rake[db:seed] # for multi-argument tasks # mina 'rake[payments:refund[arg1\,arg2]]'
@brandondrew
brandondrew / upgrading_ruby_for_rails
Last active January 3, 2023 04:46
How To Upgrade Ruby for your Rails App, Locally & on a Server with Passenger
Overview
--------
Consider the commands given to be examples, not to necessarily be precisely
what you will use. They were based on my circumstances, in which
* my local platform is macOS,
* where Homebrew is the de facto package manager;
* my laptop (and the server) are managing Ruby with rbenv;
* vim is my remote editor of choice, and an acceptable local editor; and
@letiesperon
letiesperon / Rails credentials
Last active January 18, 2024 21:08
What I need to know about Rails 6 credentials and master key
The credentials are stored in the "credentials.yml.enc" file, encrypted.
To decrypt the credentials file, you need a master key that is set on either:
* config/master.key file (for local development)
* ENV["RAILS_MASTER_KEY"] (for deployed environments)
What should you commit?
* The file config/master.key should be ignored in gitignore (you should not commit the master key)
* The file credentials.yml.enc should be commited along with the codebase (but don't worry, only those who have the master key can decrypt it)