Skip to content

Instantly share code, notes, and snippets.

View zmajstor's full-sized avatar

Zoran Majstorovic zmajstor

View GitHub Profile
@zmajstor
zmajstor / dry_scope.rb
Created February 10, 2014 11:20
AR DRY scoping of the nested models
class Collection < ActiveRecord::Base
has_many :products
scope :live, where("collections.end_date IS NOT NULL AND collections.end_date >= ?", Time.now.to_date)
end
class Product < ActiveRecord::Base
belongs_to :collection
# how to DRY this .where ?
scope :launched, joins(:collection).where("collections.end_date IS NOT NULL AND collections.end_date >= ?", Time.now.to_date)
@zmajstor
zmajstor / _collection.html.erb
Last active August 29, 2015 13:56
how to wait for jQuery .append to finsh
<div class="card">
<%= image_tag (collection.designer.cover_image_url), class: "center-block" %>
<div class="card-hover">
<span class="card-overlay">
<%= collection.designer.fullname %><br>
<%= collection.designer.live_collection.name %><br>
<%= collection.designer.location %>
</span>
</div>
</div>
@zmajstor
zmajstor / aviary_uploader.rb
Last active August 29, 2015 13:57
CarrierWave upload with Aviary and FileReader
# encoding: utf-8
class AviaryUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
# storage :file
@zmajstor
zmajstor / routes.rb
Created April 28, 2014 18:51
jQuery Autocomplete with Rails
get 'users_autocomplete', to: 'users#autocomplete'
@zmajstor
zmajstor / build_cn.rb
Created May 8, 2014 11:10
build string based on input strings and regex
# input parameters (from LDAP or device attributes SERIAL, UDID) ...
param1 = "abcdefgh12345678"
param2 = "qwertyui09876543"
param3 = "asdfghjkl@zxcvbnml"
# take first 5 non-whitespace character
regex1 = /^\S{5}/
# take last 4 non-whitespace character
regex2 = /\S{4}$/
@zmajstor
zmajstor / find_duplicates.rb
Created May 20, 2014 21:15
Find_by_SQL rows with duplicate attribute value
Device.find_by_sql "select udid, count(*) from devices group by udid having count(*) > 1"

Keybase proof

I hereby claim:

  • I am zmajstor on github.
  • I am zmajstor (https://keybase.io/zmajstor) on keybase.
  • I have a public key whose fingerprint is 051D F53E 7747 101E 4A93 6AD8 C8CD 3A5E 8BFD BF3D

To claim this, I am signing this object:

class Payload
def general_payload
payload = Hash.new
payload['PayloadVersion'] = 1
payload['PayloadUUID'] = rand(10)
payload['PayloadOrganization'] = organization
payload
end
end
@zmajstor
zmajstor / _feather_editor.html.erb
Created August 2, 2014 10:06
rails-carrierwave-aviary image upload
<!-- Load Feather code -->
<!-- <script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script> -->
<script type="text/javascript" src="https://dme0ih8comzn4.cloudfront.net/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: 'API_KEY',
// apiKey: '<%= ENV['AVIARY_KEY'] %>',
apiVersion: 3,
# builder pattern in ruby
# inspired by https://github.com/tboyko/ios_config
# and http://blog.rubygeek.com/2009/11/24/builder-pattern-in-ruby/
module Payload
# provide base for building Payloads in Configuration Profile
class Base
def build
raise ArgumentError, "missing identifier" unless identifier