Skip to content

Instantly share code, notes, and snippets.

@MTen
MTen / gift.json
Created March 17, 2016 20:10
Example of how to use oneOf on a required property instead of on the object body.
{
"type": "array",
"items": {
"type": "object",
"description": "A product or piece of merchandise purchased with, points.",
"properties": {
"giftID": {
"type": "string",
"description": "A unique ID for differentiating gift objects"
@MTen
MTen / gist:e5a5af911d855b8731d3
Created July 23, 2015 19:44
android screenshot from the command line
#Add this to your .bash_profile or .bash_alias and source ~/.bash_<<your location>>
#This uses the android debug bridge to screen cap.
#Usage: $ androidScreenshot <name of file>
#i.e. androidScreenshot myAwesomeScreenshot
androidScreenshot() {
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > $1.png
echo "$1.png has been saved"
}
@MTen
MTen / gist:8412919
Created January 14, 2014 04:11
Heroku error message when deploying new app to heroku. "We're sorry, but something went wrong." Second time I've gotten this message, the first time I thought it was a massive git failure on my part, now I'm just confused.
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Using rake (10.1.1)
Using i18n (0.6.1)
Using multi_json (1.8.4)
Using activesupport (3.2.13)
@MTen
MTen / Rails CR -UD
Created January 9, 2014 01:58
This is how I understand rails CR .app without U or D.
A Rails CR .app with out the U or D
Create
Adding new records or objects to your database
.new(:stuff => “things")
The most basic way to create a new model object is with the new method. This record only lives in memory until .save is called on the object. Without calling .save on the object it will not be recorded to the database.
Possible applications: creating a new model object that lives in sessions until the user does a final submit action.
.create(:morestuff => “other things”)
This will create and save an object in one fell swoop. In this case its passing a hash of attributes to the create method. Normally we need to denote a hash with curly braces { :large_intestine => “poop" } but when a hash is the last argument of a Ruby method the braces are optional. You can also create a hash and then pass it through the .create method.
@MTen
MTen / Rspec instead of TestUnit
Last active April 14, 2020 00:29
This is a flag hack for the "rails new <name_of_app>" command. It needs to be added to your .bash_profile and it will remove TestUnit, add the rspec-rails gem to your Gemfile, change directory into your app, re-bundle, and then generate a rspec folder. The syntax is "rails new <name_of_app> -rspec" I added pg to this and config database.yml
Adding a -rspec flag to rails. Also establishes and
rails() { if [[ $1 == "new" && $3 == "-rspec" ]]; then add_rspec $2; else command rails "$@"; fi; }
function add_rspec(){
command rails new $1 -d postgresql -T; #delete -d postgresql if you don't want pg
command chmod 664 $1/Gemfile;
echo -e "\n#Because rspec is better than Test::Unit. Or so I'm told.\ngem 'rspec-rails'" >> $1/Gemfile;
command chmod 644 $1/Gemfile;
command cd $1;
@MTen
MTen / gist:6893541
Created October 8, 2013 23:24 — forked from jleo3/gist:6893539
[1] pry(main)> Book
=> Book(id: integer, title: string, author: string, abstract: text, created_at: datetime, updated_at: datetime)
[2] pry(main)> Book.create title: "Who Stole My Cheese?"
(0.1ms) begin transaction
SQL (5.1ms) INSERT INTO "books" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00], ["title", "Who Stole My Cheese?"], ["updated_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00]]
(14.9ms) commit transaction
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">
[3] pry(main)> Book.find(4)
Book Load (0.3ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 4]]
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">