Skip to content

Instantly share code, notes, and snippets.

View philcrissman's full-sized avatar

Phil Crissman philcrissman

View GitHub Profile
@philcrissman
philcrissman / dock
Created June 14, 2019 20:54
Attach to a docker container with less typing
#!/usr/bin/env ruby
class DockerAttacher
attr_reader :docker_container
def initialize(docker_container)
if docker_container.nil?
puts "Usage: dock [container_id]\nGet container id with `docker ps`"
else
@docker_container = docker_container
@data = File.read("./input.txt").split("\n").map{|n| n.split(": ").map(&:to_i)}.to_h
@firewall = Array.new(99)
@firewall = @firewall.each_with_index.map{|n,i| next if @data[i].nil?; ((0..@data[i]-1).to_a + (1..@data[i]-2).to_a.reverse).cycle}
@results = (0..98).map{|n| n if @firewall.map{|e| next if e.nil?; e.next}[n] == 0}.select{|n| n if !n.nil?}
@severity = @results.map{|i| i * @data[i]}.inject(&:+)
require 'minitest/autorun'
require 'minitest/emoji'
class Version
def self.next_version version
next_version_3 version
end
def self.next_version_1 version
number_as_string = version.split(".").join('')
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooooooooooooooooooooooooo+:::++o::+++++ooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooo:::::::+o+:::::+::+++ooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooooooooooooooooooooooo::::::::::o+:+::::::::::++ooooooooooooooooooooooooooooooo|
|oooooooooooooooooo+~~::::+++oooooooooooooo::::::::::::o+::::+:::::::::+ooooooooooooooooooooooooooooo|
|ooooooooooooooooooo.~~~.~.~~~~~~::::ooooo:~::::::::::~+o+::::::::::::::+oooooooooooooooooooooooo
<!--
.:iir:,
:iYu111u2YLjYiri
..iLUU5qOMMOOEZXX15uuJ21uvqjJ7i.
.:7J5FN0OGMOMZZEZE0PPSSFF1551ujYJYuY72U7v7vrr:.
:2EMOM8OZZ0NPXSF1S5k5FU1uUU1u2U12UJJLjJYv2uv7L7rrvLv:
.UMM0qSS111S15U521u1U1uUuUuUU2u2U1u2u15uLLv. 7Li vv7ir;vL7:
:5OGS212511U51125UUuuU2u2UUU22Fu225152Sr:ir7,. ,@B7 rv7rri;r77;.
@philcrissman
philcrissman / nslookuping
Created February 20, 2013 16:33
nslookup ing the starwars traceroute. see `traceroute obiwan.scrye.net`
irb
1.9.3p194 :001 > ip2 = '206.214.251.'
=> "206.214.251."
1.9.3p194 :002 > (0..254).each{|octet| x= `nslookup #{ip2}#{octet}`.match(/\tname = (.*)/); puts x.captures.first unless x.nil? }
Episode.IV.
A.NEW.HOPE.
It.is.a.period.of.civil.war.
Rebel.spaceships.
striking.from.a.hidden.base.
have.won.their.first.victory.
@philcrissman
philcrissman / wat
Created March 21, 2012 20:40
Proposed new framework structure
λ ls -al
total 0
drwxr-xr-x 14 pcrissman staff 476 Mar 21 15:42 .
drwxr-xr-x 9 pcrissman staff 306 Mar 21 15:38 ..
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:38 Appfile
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:42 Configfile
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:38 Docfile
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:42 Featurefile
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:38 Filefile
-rw-r--r-- 1 pcrissman staff 0 Mar 21 15:38 Gemfile
** Lion Users: Xcode Version 4.2.x for OS X Lion works only for ruby 1.9.3-p0 (or higher).
It currently fails to build several other rubies and gems, as well as several Homebrew and
Macports packages. Xcode Version 4.1 (4B110) works.
@philcrissman
philcrissman / activemerchant.rb
Created October 26, 2011 03:17
So, you want to put an activemerchant CreditCard in a Formtastic form?
module ActiveMerchant
module Billing
class CreditCard
extend ActiveModel::Naming
include ActiveModel::Conversion
def persisted?
false
end
@philcrissman
philcrissman / gist:1281853
Created October 12, 2011 17:11
destroy_all, with conditions.
> # on a model, works fine.
> Voucher.destroy_all(:user_id => nil)
=> # works as expected; returns an array of the records it destroyed, and said records have been deleted.
> # on a collection:
> wv.voucher_restrictions.destroy_all(:restriction_id => 108)
=> ArgumentError: wrong number of arguments (1 for 0)
> # but... this works:
> wv.voucher_restrictions.where(:restriction_id => 108).destroy_all