Skip to content

Instantly share code, notes, and snippets.

View SingularityMatrix's full-sized avatar

SingularityMatrix

  • Earth.
View GitHub Profile
defaults delete ~/Library/Preferences/com.teamviewer.teamviewer9.plist
defaults delete ~/Library/Preferences/com.teamviewer.teamviewer9.Machine.plist
sudo defaults delete /Library/Preferences/com.teamviewer.teamviewer9.plist
rm -f ~/Library/Preferences/com.teamviewer.teamviewer9.plist
rm -f ~/Library/Preferences/com.teamviewer.teamviewer9.Machine.plist
sudo rm -f /Library/Preferences/com.teamviewer.teamviewer9.plist
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@SingularityMatrix
SingularityMatrix / singleton.rb
Last active August 29, 2015 14:20
Using Ruby singleton library
require 'singleton'
class User
include singleton
end
>> User.instance
=> #<User:0x007fe75492fea8>
>> User.instance
=> #<User:0x007fe75492fea8>
@SingularityMatrix
SingularityMatrix / reuse_instance.rb
Last active August 29, 2015 14:20
Reuse a User instance for a given accesscode
class User
def self.new(accesscode)
@cache ||= {}
@cache[accesscode] ||= super(accesscode)
end
def initialize(accesscode)
@accesscode = accesscode
end
end

How many servings should I eat per day?

  • Fruit = 1-2 servings
  • Animal protein = 4 - 6 servings
  • Healthy fats = 5 - 9 servings
  • Healthy vegetables = 6 - 11 servings

How should I allocate my calories per day?

  • Healthy fats = 50%
@SingularityMatrix
SingularityMatrix / annotate_barcodes.rb
Created May 30, 2015 15:55
Create and annotate barcodes in Ruby
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/png_outputter'
require 'mini_magick'
require 'benchmark'
# Build a sample barcode
def build_barcode(prod, supplier_code, batch_no)
bar_code = prod + "-" + supplier_code + "-"+ batch_no
bar_code_image = bar_code.delete("/") # Clear all /'s in the code if any ..
@SingularityMatrix
SingularityMatrix / batch_api_requests.rb
Last active August 29, 2015 14:22
Batch API requests using REST API in Ruby on Rails [stress free way]
# app/controllers/api/v1/stockins_controller.rb
module Api
module V1
class StockinsController < ActionController::Base
before_filter :restrict_access
respond_to :json
def index
respond_with Stockin.all
end
@SingularityMatrix
SingularityMatrix / barcodes_in_ruby.rb
Created June 16, 2015 13:35
Working with Barcodes in Ruby
# To be written