Skip to content

Instantly share code, notes, and snippets.

@thatandyrose
thatandyrose / gist:4afd79188904999b3e581df6a99ef0f9
Created November 11, 2019 10:36
vagrant global-status --debug
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
Loading personal and system profiles took 1057ms.
C:\Users\thata> vagrant global-status --debug
INFO global: Vagrant version: 2.2.5
INFO global: Ruby version: 2.4.6
INFO global: RubyGems version: 2.6.14.4
@thatandyrose
thatandyrose / some_object.rb
Created January 15, 2015 16:35
dynamic inheritence
class SomeObject
def initialize(object_to_extend)
@object_to_extend = object_to_extend
end
def respond_to?(sym, include_private = false)
super(sym, include_private) || object_to_extend_responds?(sym)
end
@thatandyrose
thatandyrose / gtfs_import.rb
Created October 8, 2014 15:22
GTFS importer snippets
require 'csv'
require 'open-uri'
module GTFS
class AgencyImporter < BaseImporter
def import(agency_ids = [])
options = {
document_build: ->(row){{agency_id: row[:agency_id], agency_timezone: row[:agency_timezone], agency_name: row[:agency_name]}}
}
{
"tree" => {
"id" => "26",
"name" => "My Awesome Tree",
"variable_ids" => ["ValueDriver-1"],
"variables" => [
{
"id" => "ValueDriver-1",
"name" => "My Value Driver",
"type" => "ValueDriver",
[
{
"value": {
"id": 1,
"value_driver_id": 1,
"position": 0,
"value_id": "ValueDriver-2",
"next_operand": "*",
"created_at": "2014-04-15T06: 44: 38.724Z",
"updated_at": "2014-04-15T06: 44: 38.724Z"
@thatandyrose
thatandyrose / viewport.js
Created September 6, 2013 00:03
js snippet to keep element the size of the viewable port. Note, this require a valid DOC type in the document.
$(document).ready(function(){
set_size()
});
$(window).resize(function(){
set_size();
});
function set_size(){
var h = $(window).height();
@thatandyrose
thatandyrose / numeric.rb
Created August 18, 2013 06:42
A little percentage helper for all ruby numbers!
class Numeric
#usage:
#9.53.as_percent(11,2) => 86.64
#9.53.as_percent(11,1) => 86.6
#9.53.as_percent(11) => 87
def as_percent(max,precision = 0)
((self.to_f/max)*100).round(precision)
end
end
@thatandyrose
thatandyrose / TimeSpan.rb
Last active December 20, 2015 19:08
very simple class to make calculation spans of time super easy. Inspired by .NET's TimeSpan class, still lots of room for improvement! For Rails I recommend putting it in /config/initializers.
class TimeSpan
attr_accessor :milliseconds
def self.from_milliseconds(milliseconds)
me = TimeSpan.new
me.milliseconds = milliseconds
return me
end
def self.from_seconds(seconds)
@thatandyrose
thatandyrose / Hash.rb
Last active December 20, 2015 11:59
nicer syntax for creating new lovely OpenStructures (http://www.ruby-doc.org/stdlib-2.0/libdoc/ostruct/rdoc/OpenStruct.html)
class Hash
def structify
return OpenStruct.new(self)
end
end
@thatandyrose
thatandyrose / string.rb
Created June 6, 2013 10:46
Add some grammar helpers to your String!
class String
def articleize
me = self.downcase
an_startswith = ['a','e','i','o','u']
an_exceptions = ['unit'] #add more when you think of them!
if me.start_with?(*(an_startswith + an_exceptions))
return "an #{self}"
else
return "a #{self}"