Skip to content

Instantly share code, notes, and snippets.

############
# PLASE FILL
############
secret_key = "APPLICATION_SECRET_KEY_INSERT"
application = "APPLICATION_KEY_INSERT"
instance = "INSTANCE_INSERT"
############
# THAN RUM
@ondrejbartas
ondrejbartas / redis_connect.rb
Created July 29, 2011 09:28
Connection to redis
class RedisConnect
@@db_redis = nil
@@db_adtext_redis = nil
def self.redis
if @@db_redis.nil?
config = YAML.load_file('config/database.yml')[ENV['RACK_ENV']]
@@db_redis = Redis.new(:host => config["host"], :port => config["port"], :db => config["db"])
end
return @@db_redis
@ondrejbartas
ondrejbartas / redis_connect.rb
Created July 29, 2011 09:28
Connection to redis
class RedisConnect
@@db_redis = nil
@@db_adtext_redis = nil
def self.redis
if @@db_redis.nil?
config = YAML.load_file('config/database.yml')[ENV['RACK_ENV']]
@@db_redis = Redis.new(:host => config["host"], :port => config["port"], :db => config["db"])
end
return @@db_redis
@ondrejbartas
ondrejbartas / gist:1943795
Created February 29, 2012 19:29
Substring UNICODE in ruby 1.8.7
puts "ščřžýáíéáýžřčřžýáíážřýášžýěáč".scan(/./mu)[0,10].join
@ondrejbartas
ondrejbartas / gist:1943804
Created February 29, 2012 19:29
Translate diacritics and unicode chars to ASCII
# -*- encoding : utf-8 -*-
require "active_support"
require 'active_support/inflector'
puts ActiveSupport::Inflector::transliterate("Nějaký ten string ščřžýáíé")
def show_nfi_tfl percent
if percent.nil?
""
elsif percent < 0
tfl = "tfl_3critical"
elsif percent < 10
tfl = "tfl_3red"
elsif percent < 20
tfl = "tfl_2yellow"
@ondrejbartas
ondrejbartas / _ios_icons.html.erb
Created May 31, 2013 10:40
apple-icon-setup.html
<!-- iPad Settings -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- iOS ICONS -->
<link rel="apple-touch-icon" sizes="144x144" href="<%= image_path("apple_icons/icon-144.png") -%>" />
<link rel="apple-touch-icon" sizes="114x114" href="<%= image_path("apple_icons/icon-114.png") -%>" />
<link rel="apple-touch-icon" sizes="72x72" href="<%= image_path("apple_icons/icon-72.png") -%>" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="<%= image_path("apple_icons/icon-144.png") -%>" />
# -*- encoding : utf-8 -*-
require 'tire'
require 'tire/http/clients/curb'
Tire.configure do
# # logger 'log/elasticsearch.log', :level => 'debug' if Bandit.env == 'development'
# #logger STDOUT, :level => 'debug'
client Tire::HTTP::Client::Curb
end
require 'json'
package = JSON.parse(File.open('./package.json').read)
mainfiles = Dir['./node_modules/*'].map{|f| "#{f}/package.json"}.select{|f| File.exist?(f)}.map{|f| JSON.parse(File.open(f).read)}
organizationfiles = Dir[*Dir['./node_modules/*'].select{|f| !File.exist?("#{f}/package.json")}.map{|x| "#{x}/*"}].map{|f| "#{f}/package.json"}.select{|f| File.exist?(f)}.map{|f| JSON.parse(File.open(f).read)}
files = mainfiles | organizationfiles
out = {
'devDependencies' => {},
'dependencies' => {}
@ondrejbartas
ondrejbartas / gist:3526110
Created August 30, 2012 10:45
Make sessions work in Rack::Test with Sinatra's sessions
# Put this in your test helper file
# This works when using the default Sinatra sessions (i.e. enable :sessions)
# (helper preamble not included)
require 'securerandom'
class Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application # or the name of your modular app