Skip to content

Instantly share code, notes, and snippets.

View DamirSvrtan's full-sized avatar
🎖️

Damir Svrtan DamirSvrtan

🎖️
View GitHub Profile
@DamirSvrtan
DamirSvrtan / creative_connect.rb
Created November 16, 2013 15:05
Short script so my linux mint 15 laptop can automatically connect to my creative D80 bluetooth speakers via bluez-tools (sudo apt-get install bluez-tools).
BLUETOOTH_MAC_ADDRESS = "00:02:02:33:B1:87"
SINK_NAME = "bluez_sink.00_02_02_33_B1_87"
def connect
`bt-audio -c #{BLUETOOTH_MAC_ADDRESS}`
end
def disconnect
`bt-audio -d #{BLUETOOTH_MAC_ADDRESS}`
end
@DamirSvrtan
DamirSvrtan / gem_builder.sh
Last active December 31, 2015 21:29
gem_builder.sh
if [ -z $1 ]; then
GEM_NAME=${PWD##*/}
else
GEM_NAME=$1
fi
GEMSPEC="$GEM_NAME.gemspec"
if [ -f $GEMSPEC ];then
gem build $GEMSPEC
@DamirSvrtan
DamirSvrtan / nojz
Last active February 2, 2023 21:58
Bluetooth speaker connection script. Out of convenience written in Ruby.
#!/usr/bin/env ruby
require 'open3'
class NojzError < StandardError
def initialize(msg)
@msg = msg
super(msg)
end
@DamirSvrtan
DamirSvrtan / aliases.sh
Last active January 4, 2016 01:49
Aliases
alias productive='git log --since="today" --oneline | sed "s/^\w\+/*/g"'
@DamirSvrtan
DamirSvrtan / rails_flash_messages.rb
Created March 29, 2014 16:41
Rails Flash Messages Helper
def flash_messages
content_tag :div, class: "flash-messages" do
flash.map do |key, value|
content_tag :div, class: "alert alert-dismissable alert-#{key}" do
content_tag(:span, '&times;'.html_safe, class: :close, 'data-dismiss' => 'alert') + value
end
end.join().html_safe
end
end
Returning an array as a response:
[200, {'Content-Type' => 'text/html'}, ["<h1>Hello!</h1>"]]
Benchmark:
10000 runs
0.037738 seconds total
0.0037738 millisec/run
With a controller rendering a template with erb:
@DamirSvrtan
DamirSvrtan / gist:ae294ddf30f4ab740473
Last active August 29, 2015 14:01
Redis Store Stormpath
stormpath_client = Stormpath::Client.new(api_key: api_key, cache: {
regions: {
applications: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} },
directories: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} },
groups: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} }
}
})
```ruby
"SERVER_SOFTWARE"=>"thin 1.6.2 codename Doc Brown",
"SERVER_NAME"=>"localhost",
"rack.version"=>[1, 0],
"rack.errors"=>#<IO:<STDERR>>,
"rack.multithread"=>false,
"rack.multiprocess"=>false,
"rack.run_once"=>false,
"REQUEST_METHOD"=>"GET",
"REQUEST_PATH"=>"/",
@DamirSvrtan
DamirSvrtan / server-setup.sh
Last active August 29, 2015 14:03
Basic Server Setup
pretty_echo() {
echo_length=${#1}
stars=""
star_length=$(($echo_length+8))
for i in $(seq 1 $star_length); do
stars="$stars*"
done
echo "\n"; echo "$stars"; echo "*** $1 ***"; echo "$stars"; echo "\n"
};
@DamirSvrtan
DamirSvrtan / app_template.rb
Last active August 29, 2015 14:05
Rails application generator template
### Rails app generator template. Run it:
### rails new _app_name_ -m https://gist.githubusercontent.com/DamirSvrtan/28a28e50d639b9445bbc/raw/app_template.rb
remove_file "README.rdoc"
create_file "README.md", "Development: run ./bin/setup"
run 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss'
database_type = ask("Do you want to use postgres or mysql?", limited_to: ["pg", "mysql"])
adapter = if database_type == 'pg'