Skip to content

Instantly share code, notes, and snippets.

View miharekar's full-sized avatar

Miha Rekar miharekar

View GitHub Profile
@miharekar
miharekar / gist:4386699
Created December 27, 2012 08:57
Simple way to get GMT date from ISO8601 date in Objective C
- (NSString *)getGMTDateStringfromISO8601DateString:(NSString *)ISODateString
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
ISODateString = [ISODateString stringByReplacingOccurrencesOfString:@":" withString:@"" options:0 range:NSMakeRange([ISODateString length]-5, 5)];
NSDate *ISODate = [formatter dateFromString:ISODateString];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
@miharekar
miharekar / Uncrustify config
Created February 20, 2013 08:51
My uncrustify config for Objective-C. Braces on single line on methods, same line on everything else, indent with spaces,… Check it out ;)
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.3 (176)
#
# Alignment
# ---------
## Alignment
@miharekar
miharekar / simple_form_bootstrap.rb
Last active December 23, 2015 23:39
Simple Form Bootstrap 3 initializer
inputs = %w[
CollectionSelectInput
DateTimeInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
]
@miharekar
miharekar / bootstrap_breadcrumbs_builder.rb
Last active December 24, 2015 07:39 — forked from riyad/bootstrap_breadcrumbs_builder.rb
Bootstrap 3 compatible breadcrumbs builder for breadcrumbs_on_rails gem.
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder %>
#
# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:
# config.autoload_paths += Dir["#{config.root}/lib/"]
#
class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
def render
return '' if @elements.empty?
@context.content_tag :ol, class: 'breadcrumb' do
@miharekar
miharekar / heroku_import.thor
Last active December 30, 2015 21:49
A simple thor script for imporing Heroku database into localhost. This is the original: http://antonzolotov.com/2012/03/04/rails-scripts-clone-heroku-database-to-development.html
#!/usr/bin/env ruby
module HerokuImport
class Db < Thor
method_option :keep, :type => :boolean, :default => false
method_option :remote, :type => :string, :default => "heroku"
method_option :host, :type => :string, :default => "localhost"
method_option :user, :type => :string, :default => `whoami`.strip
method_option :dbname, :type => :string
method_option :dump, :type => :string, :default => "latest.dump"
class EmailDomainValidator
attr_reader :domain
def initialize(email)
email = Mail::Address.new(email_string)
@domain = email.domain
end
def valid?
email.domain.present? && (registered? || operational?)
@miharekar
miharekar / .gitconfig
Last active August 29, 2015 14:06
dotfiles
[user]
name = Miha Rekar
email = info@mr.si
[core]
editor = atom -nw
[color]
ui = 1
[alias]
s = status -sb
c = commit
@miharekar
miharekar / gem_make.out
Created September 24, 2014 09:38
gem install sigar -v '0.7.2' failing
/Users/mrfoto/.rubies/ruby-2.0.0-p247/bin/ruby -r ./siteconf20140924-20429-1pmwjcu.rb extconf.rb
Ruby platform=x86_64-darwin14.0.0
rbsigar_generated.rx needs update
generating rbsigar_generated.rx
fatal: Not a git repository (or any of the parent directories): .git
../../src/sigar.c -> sigar.c
../../src/sigar_cache.c -> sigar_cache.c
../../src/sigar_fileinfo.c -> sigar_fileinfo.c
../../src/sigar_format.c -> sigar_format.c
../../src/sigar_getline.c -> sigar_getline.c
@miharekar
miharekar / scraper.rb
Created November 11, 2014 20:18
apparatus twitter usernames
require 'nokogiri'
require 'open-uri'
require 'json'
require 'csv'
URL = 'http://apparatus.si/oddaja/pogovor/page/%d/'
def last_page
doc = Nokogiri::HTML(open(URL%1))
pagination = doc.css('.archive-pagination a')
@miharekar
miharekar / struct_vs_class.rb
Created March 6, 2015 17:08
Ruby: Struct vs Class performance
require 'benchmark/ips'
Benchmark.ips do |x|
SingleFilterStruct = Struct.new(:method, :values) do
def call(value)
Array(value).any? { |v| v.send(method, *values) }
end
end
class SingleFilterClass