Skip to content

Instantly share code, notes, and snippets.

View cilim's full-sized avatar

Marko Ćilimković cilim

View GitHub Profile
@cilim
cilim / client_setup.rb
Created November 9, 2016 09:27
Stormpath Ruby SDK client initialization with custom caching options for Redis
api_key = Stormpath::ApiKey.new(ENV['test_api_key_id'], ENV['test_api_key_secret'])
client = Stormpath::Client.new(
api_key: api_key,
cache: {
store: Stormpath::Cache::RedisStore,
store_opts: {
host: 'localhost',
port: 7777
},
regions: {
@cilim
cilim / application_controller.rb
Last active February 10, 2017 15:34
How to add timeoutable to Stormpath in a Rails application
class ApplicationController < ActionController::Base
include Stormpath::Rails::Controller
include Timeoutable
protect_from_forgery with: :exception
def show
end
end
@cilim
cilim / comparisons.md
Last active August 27, 2019 18:56
Geocoder VS Geokit-rails comparisons

Gem Comparisons

Repo state

Geocoder Geokit-Rails
Stars 4802 1286
Issues 38 58
Open pull requests 19 1
@cilim
cilim / _form.html.erb
Created August 27, 2018 07:51
Implementation for forms that associate (un)existing parent-child relationships
<div class="row">
<div id="specification-value-name" class="col-md-12 with-tip", data-original-title="<%= t('admin.tooltips.specification_value') %>" >
<div class="form-group">
<%= f.label :value %>
<%= f.hidden_field :value, value: f.object.value, class: "js-specification-value-picker" %>
<%= hidden_field_tag :specification_key_id, product_specification.specification_key_id %>
</div>
</div>
</div>
<div class="row">
POST /api/v1/jobs
request body
```
{
"data": {
"type": "jobs",
"attributes": {
"address": "14642 Americo Mountain, Waylonfurt Republic of Korea",
"latitude": 40.735216,
@cilim
cilim / bad_ceki.xml
Created May 16, 2019 09:35
XML parser
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns2="http://www.opentravel.org/OTA/2003/05">
<SOAP-ENV:Header>
<ns1:Security>true</ns1:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:OTA_HotelAvailNotifRS TimeStamp="2017-07-20T10:47:34+00:00">
<ns2:Errors>
<ns2:Error Code="1" ShortText="Invalid Room Code : ROOM2410" Type="3"/>
</ns2:Errors>
@cilim
cilim / JsonApiDeserializer.rb
Created September 11, 2019 12:51
JsonApiDeserializer
class JsonApiDeserializer
MEDIA_TYPE = 'application/vnd.api+json'.freeze
def initialize(request)
@request = request
end
def params
deserialized_params if valid?
end
class BranchLinkAdapter
BRANCH_IO_API_URL = 'https://api.branch.io/v1/url'.freeze
def initialize(token, desktop_url)
@token = token
@key = Rails.application.secrets.branchio_key
@desktop_url = desktop_url
end
def fetch
JSON.parse(fetch_url.body)['url'] if fetch_url.code == 200
@cilim
cilim / attribute_default_block_value.rb
Created August 27, 2020 15:15
Rubocop Rails/AttributeDefaultBlockValue
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# This cop looks for `attribute` class methods that don't
# specify a `:default` option inside a block.
#
# @example
# # bad