Skip to content

Instantly share code, notes, and snippets.

View goodviber's full-sized avatar

GoodViber goodviber

View GitHub Profile
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{243}'
COLOR_DIR='%F{197}'
COLOR_GIT='%F{39}'
NEWLINE=$'\n'
setopt PROMPT_SUBST
export PROMPT='${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '
@goodviber
goodviber / gist:06dd4fa6e4b7f2aa141eefc3aa142e75
Created November 12, 2021 14:47
Gov uk form builder date error
<%= form.govuk_date_field :some_date,
legend: { text: t(".some_date", count: ordinal_number(@dose)), size: 's' },
hint_text: t('hint_texts.date', date_example: 1.week.ago.strftime('%d %m %Y')),
pre_fill_day: params.dig(:form_model, 'some_date(3i)'),
pre_fill_month: params.dig(:form_model, 'some_date(2i)'),
pre_fill_year: params.dig(:form_model, 'some_date(1i)')
%>
# /lib/extensions/gov_uk_design_system_form_builder
provider "cloudfoundry" {
api_url = var.api_url
user = var.user
password = var.password
}
terraform {
required_version = ">= 0.13.4"
required_providers {
cloudfoundry = {
source = "cloudfoundry-community/cloudfoundry"
#puts VCR.current_cassette.http_interactions.interactions.last.response.to_hash["body"]
#thing = YAML.load_file(VCR.current_cassette.file)
#puts thing["http_interactions"].last["response"]["body"]["string"].class
class OverseasCandidate < Base
attribute :telephone_number, :string
attribute :callback_date, :date
attribute "callback_date(3i)", :string
attribute "callback_date(2i)", :string
attribute "callback_date(1i)", :string
attribute :callback_time, :string
attribute :time_zone, :string
before_validation :make_a_date
class Flickr
def self.cached_request
Rails.cache.fetch "photos", :expires_in => 5.minutes do
flickr.photos.getRecent
end
end
end
@goodviber
goodviber / name_parser.rb
Last active April 8, 2020 21:09
NameParser
class NameParser
HONORIFICS = ["Mr", "Mrs", "etc"]
def self.parse_full_name(full_name)
full_name.gsub!(/[^a-z- ]/i, '') # check for invalid chars, should we downcase everything?
names = full_name.split(' ')
class Movement
attr_reader :distance
def initialize(distance)
@distance = distance
end
def move
puts "moved #{@distance} miles"
sudo -u postgres psql
psql -d template1
@goodviber
goodviber / array_flattener.rb
Last active February 24, 2020 19:40
Theorem
class ArrayFlattener
#recursive function
def flatten_this(arr)
raise ArgumentError, 'Argument is not an array' unless arr.is_a? Array
arr.each_with_object([]) do | element, flat_array |
flat_array.push *( element.is_a?(Array) ? flatten_this(element) : element )
end
end