Skip to content

Instantly share code, notes, and snippets.

View tastycode's full-sized avatar

Sasha Devol tastycode

  • Elsewhere Labs
  • New Orleans, LA
View GitHub Profile
@tastycode
tastycode / magic_struct.rb
Created January 10, 2017 17:13
MagicStruct
class MagicStruct
include ActiveModel::Validations
def initialize(hashish)
hashish.each do |key, val|
send(:"#{key}=", val)
end
end
def self.required_params(*required_keys)
#!/usr/bin/env ruby
# Usage: echo "lyrics to a song" | ./sweater.rb
# Usage: ./sweater.rb lyrics.txt
# #Input: Billie Jean Lyrics from https://play.google.com/music/preview/Tkjszhsypodj4rcjo3yfxdzfuxi?lyrics=1&utm_source=google&utm_medium=search&utm_campaign=lyrics&pcampaignid=kp-lyrics&u=0#
# #Output
# lee baas roar pike they booty dean sum grey groovy seen
# lye bred dont mined slut glut crew flew jeanne my dram duh dunne
# chew brill trance john huh drawer chin duh crowned
# v fed cai gram uh mun shoo grill vance hon ca lore when huh found
#
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
@tastycode
tastycode / readme.md
Last active November 4, 2019 22:53
Automating Shipping Through Shyp

Shyp is awesome. They can pick up what you have to ship in minutes and take care of all the packing and addressing. Their rates are as cheap as you can get and they have a custom boxing process that minimizes void space.

This would be great for shipping things in bulk if it weren't for them not having an API, or any other means to enter shipments other than their iPhone app.

I had 100 shipments to make, so I threw together this script to automate the creation of the shipments. This isn't for the faint of heart, you'll have to know how to create a transparent HTTPS proxy and hook your iPhone up to it so you can get your session and authorization headers. I'm not going to go into that, but once you get the appropriate headers, put them in a file called shyp.headers. You'll also need to create a shipment manually through the app in order to get a PICKUP_ID. Once you have that, just add your addresses to the array called addresses and run the script. I also didn't want to figure out

@tastycode
tastycode / gist:f66785f3915772b274ef
Created May 27, 2015 17:33
Find misplaced console.logs
> var ConsoleLogOld = console.log;
undefined
> console.log = function() {
... ConsoleLogOld.apply(null, Array.prototype.slice.apply(arguments))
... console.trace()
... }
[Function]
> console.log("meow")
/*
meow
@tastycode
tastycode / gist:daa84c0bbdb8b2c3a63a
Created December 10, 2014 23:37
Render rails templates from javascript handlebars templates
# config/initializers/sprockets.rb
module Sprockets::Helpers::RailsHelper
def view_renderer
@view_renderer ||= begin
view_paths = Rails::Application::Configuration.new(Rails.root).paths["app/views"]
ActionView::Base.new(view_paths).tap do |renderer|
def renderer.method_missing(name, *args)
router = Rails.application.routes.url_helpers
return router.send(name, *args) if router.respond_to?(name)
@tastycode
tastycode / null.rb
Created November 18, 2014 01:21
My null object
class Null
def !@
false
end
def nil?
true
end
def present?
@tastycode
tastycode / gist:3da4984004f4b4a483c9
Last active August 29, 2015 14:09
Got a whole bunch of `fails` in your ruby codebase?
module FailClassInference
def fail(*args)
return super unless args.first.is_a?(String)
super(infer_exception_class, *args)
end
def raise(*args)
return super unless args.first.is_a?(String)
super(infer_exception_class, *args)
[ [ { title: 'A Camp with No Name (ACWNN)',
description: 'The dead horse is scarce, and we continue to beat it. Come by and sit in the desert in A Camp With No Name, where you will be told that buttered popcorn is a perfectly fantastic snow cone flavor – why would you think otherwise? (Don’t worry – there are “normal” flavors.) Look for us carting around chai or tidying up the playa with our vacuum cleaner.',
Hometown: 'Denver',
URL: 'https://www.facebook.com/pages/A-Camp-with-No-Name/259880375086?ref=hl' },
{ title: 'A Cosmic Carnivale',
description: 'Come and visit a Cosmic Carnival and may your body never miss a beat to the rhythm of this world.',
Hometown: 'Reno',
Contact: 'cosmiccarnivale@gmail.com' },
{ title: 'A Shack of Sit',
description: 'SIT HAPPENS HERE 24×7. Shady chairs & lounges: refresh, rest, meet Burners. Enjoy iced water, healthy snax, lots of activities & WiFi.',
@tastycode
tastycode / common_constants.rb
Created June 23, 2014 17:14
Common Constants
# Share constants between ruby and javascript
# Setup
# (in application.html.erb, or some place to inject javascript)
# MyApplication.constants = #{CommonConstants.to_json};
#
# Usage
# Ruby
# CommonConstants << "Math::PI"
# Javascript
# MyApplication.constants.MATH_PI