Skip to content

Instantly share code, notes, and snippets.

View alekpopovic's full-sized avatar
🏠
Working from home

Aleksandar Popovic alekpopovic

🏠
Working from home
View GitHub Profile
@alekpopovic
alekpopovic / gist:d853810013356598e1c4d2f75515fad1
Created July 13, 2016 22:19 — forked from polimorfico/gist:4074902
Force your params encoding in Rails

If you have problems with your params encodings, use a Rack middleware to encode them before rails params parsing code is executed.

First, build a class according to the signature of a rack middleware layer.

#lib/force_params_encoding.rb
class ForceParamsEncoding
  def initialize(app)
    @app = app
  end
@alekpopovic
alekpopovic / base_controller.rb
Created August 10, 2016 16:25 — forked from dhoelzgen/base_controller.rb
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@alekpopovic
alekpopovic / doc.md
Created August 11, 2016 19:19 — forked from oelmekki/doc.md
Rails + Browserify + React + es7

1. Gemfile

gem 'browserify-rails', '1.5.0' # until fix: https://github.com/browserify-rails/browserify-rails/issues/101
gem 'react-rails'

Browserify-rails allows to use browserify within assets pipeline. React-rails is here only to allow to use #react_component (and thus, prerendering).

Note that jquery-rails can be removed from Gemfile, the npm version of jquery and jquery-ujs will be used instead.

@alekpopovic
alekpopovic / Gemfile
Created August 15, 2016 22:54 — forked from adamrobbie/Gemfile
Rails Endless pagination
gem 'will_paginate'

Rails 5 and ActionCable

Assumptions: The application already exists. You have two models article.rb and comment.rb. Articles have two attributes, title and text. Comments have two attributes, text and article_id. See these instructions if you need help getting started.

Routes

Assuming that you are nesting your :comments resources inside of :articles, mount ActionCable and make sure you have a root.

config/routes.rb

Rails.application.routes.draw do
@alekpopovic
alekpopovic / rails_route_recognizer.rb
Created September 8, 2016 17:23 — forked from bantic/rails_route_recognizer.rb
Programmatically list all routes (/paths) from within a rails app.
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# `RouteRecognizer.new.initial_path_segments`
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize
@alekpopovic
alekpopovic / azk-front-end-nginx.md
Created September 20, 2016 12:23 — forked from tuliomonteazul/azk-front-end-nginx.md
How to use Azk, Docker and Nginx for Front-end Development

Using AZK to develop your front-end code and serve with Nginx as a CDN

Motivation

Setting up an envinroment to start coding is hard. Specially if you are in a team and have to share your environment setup. Here is where [Azk] comes in. It's an orchestrator to setup your development environment. It uses the Azkfile.js to read your project's requirements and install everything using [Docker] containers. If you're familiar with [Vagrant], let's say that Azk solves the same problem but with a different approach. Instead of a monolithic, it's based on separation of concerns. We have modular containers that are lighter and allow more possibilites such as sharing setup to deploy to other environments.

When we develop front-end code nowadays, we often need a set of tools for automation. Specially for Single Page Apps. So, we often need to install [Grunt], [Gulp] or [Webpack] to run CSS processors like [Sass] or [Less] and JavaScript compilers like [Babel] for ES6/7 or [JSX] for React.

Thereafter, we need a s

@alekpopovic
alekpopovic / CreateBillingAgreement
Created October 5, 2016 16:45 — forked from xcommerce-gists/CreateBillingAgreement
How to Set Up a Reference Transaction Using Express Checkout.curl
Request
-------
Endpoint URL: https://api-3t.sandbox.paypal.com/nvp
HTTP method: POST
POST data:
USER=insert_merchant_user_name_here
&PWD=insert_merchant_password_here
&SIGNATURE=insert_merchant_signature_value_here
&METHOD=CreateBillingAgreement
&VERSION=86
@alekpopovic
alekpopovic / gist:7aaae8c8fce1fa6a651430d79df3f57a
Created October 6, 2016 09:57 — forked from nov/gist:2490428
Parallel Payment in PayPal Express Gem
require File.join(File.dirname(__FILE__), 'paypal_debugger')
Paypal.sandbox!
mode = :setup
paypal = Payment::Paypal.new
request1 = Paypal::Payment::Request.new(
:amount => 10,
:description => 'Instant Payment Request',
@alekpopovic
alekpopovic / install-php53.sh
Created January 25, 2017 12:25
How to install PHP5.2 into newest versions of Ubuntu
#!/bin/bash
## read http://askubuntu.com/questions/61101/downgrade-php-to-php5-2
## read http://www.alexweber.com.br/en/tutorials/how-install-php-52-ubuntu-1010-lucid-and-1104-natty
# sudo apt-add-repository ppa:andphe/php
# sudo apt-get update
## find sources.list and replace your dist name by "lucid" for this ppa
## read http://serverfault.com/questions/52029/how-to-force-downgrade-of-packages-on-ubuntu-karmic