Skip to content

Instantly share code, notes, and snippets.

View pmatsinopoulos's full-sized avatar
💻
Programming

Panos Matsinopoulos pmatsinopoulos

💻
Programming
View GitHub Profile
@pmatsinopoulos
pmatsinopoulos / active_support_test_unit_pass_count.rb
Created October 29, 2011 14:37
Active Support Testing to count the Passed Tests when using Test::Unit
require 'active_support/concern'
require 'active_support/callbacks'
module ActiveSupport
module Testing
module SetupAndTeardown
module ForClassicTestUnit
# This redefinition is unfortunate but test/unit shows us no alternative.
# Doubly unfortunate: hax to support Mocha's hax.
def run(result)
@pmatsinopoulos
pmatsinopoulos / bug_on_active_record_when_first_or_create
Created November 25, 2013 20:48
Demonstrates a bug on ActiveRecord that occurs when one uses `Model.where(....).first_or_create(....)`. The `where(....)` is used also in any `Model.query` that takes place before the `first_or_create! returns. In the following test, the last assertion fails.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@pmatsinopoulos
pmatsinopoulos / rspec_rails_named_routes.rb
Created January 28, 2014 20:45
How to have Rails named routes available in your RSpec specs?
RSpec.configure do |config|
include Rails.application.routes.url_helpers
# ...
end
@pmatsinopoulos
pmatsinopoulos / correct_indentation.rb
Created March 13, 2015 07:29
Gist that demonstrates the correct indentation
def choose
puts "Do you like programming? Yes, no, or maybe please."
choice = gets.chomp
case choice.downcase
when "yes"
puts "That's great!"
when "no"
puts "That's too bad!"
when "maybe"
puts "Glad you are giving it a chance!"
@pmatsinopoulos
pmatsinopoulos / fav_foods_correct_indentation
Created March 14, 2015 07:39
A Small Ruby program Teaching correct indentation
def fav_foods
food_array = []
3.times do
puts "Name a favorite food"
food_array << gets.chomp
end
p food_array
puts "Your favorite foods are #{food_array.join(", ")}"
food_array.each do |food| # do something to each element in food_array; that element is to be referred to as food
puts "I like #{food} too!" # the thing we are doing
@pmatsinopoulos
pmatsinopoulos / interactive_web_site_modal_problem
Last active August 29, 2015 14:17
Correct Bootstrap/jQuery/jQuery Media Plugin on head of an html
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Phil Jedar PortFolio</title>
<!-- CSS -- >
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
@pmatsinopoulos
pmatsinopoulos / using-variables-for-jquery
Created March 28, 2015 07:08
Using variables for jQuery
var $char_count = $("#char-count");
$char_count.html(charCount);
if (charCount > 50) {
$char_count.css("color", "red");
}
else {
$char_count.css("color", "#fff");
}
<head>
<title>Nameofapp</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
@pmatsinopoulos
pmatsinopoulos / send_signed_rat_request.rb
Last active August 29, 2015 14:26
Book&Table - Mobile API - Ruby client program using the Request a Tutor private end point
require 'rest-client'
user_id = 5
secret_key = 'secret key of user with id 5'
def calculate_canonical_string(content_type, content_md5, path, timestamp)
[ content_type,
content_md5,
path,
timestamp
@pmatsinopoulos
pmatsinopoulos / send_signed_contact_tutor_request.rb
Created August 7, 2015 07:04
Example of sending a signed request to Book&Table Mobile API when POST with body data
require 'rest-client'
user_id = 5
secret_key = 'secret key of user with id 5'
tutor_id = 105
timestamp = Time.now.utc.httpdate # Example: "Mon, 03 Aug 2015 20:15:56 GMT"
def calculate_canonical_string(content_type, content_md5, path, timestamp)