Skip to content

Instantly share code, notes, and snippets.

Zoran Majstorovic zmajstor

Block or report user

Report or block zmajstor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zmajstor
zmajstor / dry_scope.rb
Created Feb 10, 2014
AR DRY scoping of the nested models
View dry_scope.rb
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 Aug 29, 2015
how to wait for jQuery .append to finsh
View _collection.html.erb
<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 Aug 29, 2015
CarrierWave upload with Aviary and FileReader
View aviary_uploader.rb
# 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 Apr 28, 2014
jQuery Autocomplete with Rails
View routes.rb
get 'users_autocomplete', to: 'users#autocomplete'
@zmajstor
zmajstor / build_cn.rb
Created May 8, 2014
build string based on input strings and regex
View build_cn.rb
# 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
Find_by_SQL rows with duplicate attribute value
View find_duplicates.rb
Device.find_by_sql "select udid, count(*) from devices group by udid having count(*) > 1"
View keybase.md

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:

View is_it_inheritance.rb
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 Aug 2, 2014
rails-carrierwave-aviary image upload
View _feather_editor.html.erb
<!-- 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,
View ios_config_profile_builder.rb
# 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
You can’t perform that action at this time.