Skip to content

Instantly share code, notes, and snippets.

View korabh's full-sized avatar
🇽🇰

Korab Hoxha korabh

🇽🇰
View GitHub Profile
irb(main):001:0> require “scanf”
=> true
irb(main):002:0> “Mozaix LLC”.scanf(“%s%s”)
=> [“Mozaix”, “LLC”]
irb(main):003:0> “Mozaix 2017”.scanf(“%s%d”)
=> [“Mozaix”, 2017]
irb(main):001:0> require “scanf”
=> true
irb(main):002:0> “Mozaix LLC”.scanf(“%s%s”)
=> [“Mozaix”, “LLC”]
irb(main):003:0> “Mozaix 2017”.scanf(“%s%d”)
=> [“Mozaix”, 2017]
@korabh
korabh / hash_builder.rb
Last active September 14, 2020 19:34 — forked from nileshtrivedi/hash_builder.rb
HashBuilder allows you to build a Hash in Ruby similar to Builder with some enhancements
# Allows you to build a Hash in a fashion very similar to Builder. Example:
# Fork of https://gist.github.com/360506 by BrentD with some enhancements
class HashBuilder
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|^object_id$)/ }
def initialize
@hash = Hash.new
@target = @hash
end
# Allows you to build a Hash in a fashion very similar to Builder. Example:
#
# HashBuilder.build! do |h|
# h.name "Brent"
# h.skillz true
# h.location do
# h.planet "Earth"
# end
# end
#
@korabh
korabh / gist:0fa8178cade28782c033
Last active August 29, 2015 14:16
Rails.gitignore
# https://github.com/github/gitignore/blob/master/Rails.gitignore
*.rbc
capybara-*.html
.rspec
/log
/tmp
/db/*.sqlite3
/db/*.sqlite3-journal
/public/system
# by Alexander Kovtunov
# require 'benchmark'
# require 'benchmark/ips'
require './tire_user_model.rb'
#
# User.tire.index.create(:mappings => User.tire.mapping_to_hash, :settings => User.tire.settings)
#User.tire.index.reindex('users',:mappings => User.tire.mapping_to_hash,:settings => User.tire.settings)
# User.tire.index.delete
@korabh
korabh / search.rb
Last active August 29, 2015 14:05
Elasticsearch Ruby
# by Alexander Kovtunov
require 'active_support'
require 'active_record'
require 'tire' #gem install tire
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.connection.instance_eval do
create_table(:users) { |t| t.string :name; t.string :country }
@korabh
korabh / distance.rb
Last active August 29, 2015 13:58
# Calculate distance between two points.
# Google Direction API
include HTTParty
format :json
def api_key
# Your API key
end
def direciton_api_url
@korabh
korabh / gist:5363081
Created April 11, 2013 12:42
Display $hook_suffix as admin notice
add_action( 'admin_notices', 'wps_print_admin_pagehook' );
function wps_print_admin_pagehook(){
global $hook_suffix;
if( !current_user_can( 'manage_options') )
return;
?>
<div class="error"><p><?php echo $hook_suffix; ?></p></div>
<?php
}