Skip to content

Instantly share code, notes, and snippets.

View sparrow's full-sized avatar

Volodymyr Vorobiov sparrow

View GitHub Profile
@sparrow
sparrow / creation_of_a_class_for_todoapp_in_react.js
Created September 8, 2016 13:54
This is a ReactJS code snippet that we used for our blog post https://rubygarage.org/blog/react-vs-angularjs at RubyGarage. It demonstrates how we compose a JS program from functions in ReactJS. This code snippet was taken from a well-known TodoMVC application.
var TodoApp = React.createClass({
getInitialState: function () {
return {
nowShowing: app.ALL_TODOS,
editing: null,
newTodo: ''
};
},
handleChange: function (event) {
this.setState({
@sparrow
sparrow / an_angular_module_creation_with_injection_of_four_dependencies.js
Created September 8, 2016 13:56
This is an AngularJS code snippet that we used for our blog post https://rubygarage.org/blog/react-vs-angularjs at RubyGarage. It demonstrates how we inject dependencies in an Angular module. This code snippet was taken from a well-known TodoMVC application.
angular.module('todomvc')
// Angular injects four dependencies in the TodoCtrl function – $scope, $routeParams, $filter, and store;
.controller('TodoCtrl', function TodoCtrl($scope, $routeParams, $filter, store) {
'use strict';
var todos = $scope.todos = store.todos;
$scope.newTodo = '';
$scope.editedTodo = null;
// missing function code is omitted for brevity
});
@sparrow
sparrow / how_to_inject_dependencies_into_angular_module_and_avoid_issues_with_code_minification.js
Created September 8, 2016 13:58
This is an AngularJS code snippet that we used for our blog post https://rubygarage.org/blog/react-vs-angularjs at RubyGarage. It demonstrates how we inject dependencies in an AngularJS module using an $inject property. This code snippet was taken from a well-known TodoMVC application.
// an example from GitHub
angular.module('todomvc')
.controller('TodoCtrl', TodoCtrl);
function TodoCtrl(s, r, f, a) {
'use strict';
var todos = s.todos = a.todos;
s.newTodo = '';
s.editedTodo = null;
// missing function code is omitted for brevity
@sparrow
sparrow / another_example_of_how_to_inject_dependencies_into_angular_module.js
Created September 8, 2016 13:59
This is an AngularJS code snippet that we used for our blog post https://rubygarage.org/blog/react-vs-angularjs at RubyGarage. It demonstrates how we inject dependencies in an AngularJS module using an inline array annotation. This code snippet was taken from a well-known TodoMVC application.
[“$scope”, “$routeParams”, “$filter”, “store”, function TodoCtrl(s, r, f, a) { //your code goes here }];
@sparrow
sparrow / how_to_create_a_namespace_with_phpunit.php
Created September 27, 2016 13:26
This is an PHPUnit code snippet that we used for our blog post https://rubygarage.org/blog/ruby-on-rails-and-symfony-comparison at RubyGarage. It demonstrates how to create a namespace with PHPUnit. This code snippet was taken from the Symfony main website.
<?php
// tests/AppBundle/Util/CalculatorTest.php
namespace Tests\AppBundle\Util;
use AppBundle\Util\Calculator;
class CalculatorTest extends \PHPUnit_Framework_TestCase
{
public function testAdd()
{
@sparrow
sparrow / test_subscription_with_rspec.rb
Created September 27, 2016 13:27
This is an Rspec code snippet that we used for our blog post https://rubygarage.org/blog/ruby-on-rails-and-symfony-comparison at RubyGarage. It demonstrates how to test subscription with Rspec. This code snippet was fully written by web developer at RubyGarage.
Rspec.describe Subscription do
describe ".create_and_request_confirmation(params)" do
it "creates an unconfirmed subscription with the given params" do
params = { email: "subscriber@somedomain.tld", start_on: "2015-01-31" }
Subscription.create_and_request_confirmation(params)
subscription = Subscription.first
expect(subscription.confirmed?).to eq(false)
expect(subscription.email).to eq(params[:email])
expect(subscription.start_on).to eq(Date.new(2015, 1, 31))
@sparrow
sparrow / paypal_express_checkout.rb
Created October 11, 2016 09:15
This is a Ruby code snipped that we used for our blog post https://rubygarage.org/blog/how-to-integrate-paypal-into-spree at RubyGarage. It demonstrates how to set up the autocapture feature for Paypal Express Checkout. This code snippet is taken from the Paypal website.
class PaypalExpressCheckout < Spree::PaymentMethod
def auto_capture?
false
end
end
@sparrow
sparrow / console
Created October 11, 2016 09:43
This code uses Bundler to run migrations for the PayPal Express Checkout gem. We used this command for our blog post https://rubygarage.org/blog/how-to-integrate-paypal-into-spree at RubyGarage.
$ bundle exec rails g spree_paypal_express:install
@sparrow
sparrow / console
Created October 11, 2016 09:44
This Bundler command will install the PayPal Express Checkout gem to your Ruby on Rails project. We used this command in our blog post https://rubygarage.org/blog/how-to-integrate-paypal-into-spree at RubyGarage
$ bundle install
@sparrow
sparrow / Gemfile
Created October 11, 2016 09:45
This code will add the PayPal Express Checkout gem to your Spree project. We used this code in our blog post https://rubygarage.org/blog/how-to-integrate-paypal-into-spree at RubyGarage
gem 'spree_paypal_express', github: 'spree-contrib/better_spree_paypal_express', branch: '3-0-stable'