Redis is my favourite key/value store; it’s flexible, easy to set up and insanely fast. [EventMachine][] is a popular Ruby library for doing asynchronous I/O using an event loop. Bindings already [exist][em-redis] for accessing a Redis server using EM’s async-I/O (courtesy of Jonathan Broad), but unfortunately the resulting code has to use [Continuation-Passing Style][cps] via Ruby blocks. A very basic example of what that looks like follows:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
# Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks | |
after 'deploy:finalize_code', 'deploy:web:disable' | |
after 'deploy:start', 'deploy:web:enable' | |
namespace :deploy do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby_block "rvm use default" do | |
block do | |
Chef::Mixin::Command.popen4('bash -l -c "rvm use default && env"') do |p,i,o,e| | |
o.each_line do |line| | |
next if line.nil? | |
line.chomp! | |
next if line.empty? | |
env_bits = line.split("=") | |
ENV[env_bits[0]] = env_bits[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hack for the chef - we cannot read file in http_request resource | |
ruby_block "Set attributes for http request for #{database[:name]} #{database[:kind]}" do | |
block do | |
request = resources(:http_request => "Create backup record for #{database[:name]} #{database[:kind]}") | |
request.message({:backup => {:filename => compressed_file_name, :kind => database[:kind], :size => File.size(compressed_file_path)}}) | |
end | |
end | |
http_request "Create backup record for #{database[:name]} #{database[:kind]}" do | |
url "http://some-url/backups" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
# | |
# s3up.py | |
# 2010-2011, Mike Tigas | |
# https://mike.tig.as/ | |
# | |
# Usage: | |
# s3up filename | |
# Uploads the given file to the DEFAULT_BUCKET (see below) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bluepill.define_process_condition(:running_time) do | |
def initialize(options = {}) | |
@below = options[:below] | |
end | |
def run(pid) | |
started = `ps -p #{pid} -o command`.match(/since (\d+)/)[1].to_i | |
Time.now - Time.at(started) | |
rescue | |
0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
start_time = Time.now | |
SOURCE_DB = { | |
:name => 'db_name', | |
:user => 'db_user', | |
:password => 'db_pass', | |
:host => 'localhost' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update, upgrade and install development tools: | |
apt-get update | |
apt-get -y upgrade | |
apt-get -y install build-essential | |
apt-get -y install git-core | |
# Install rbenv | |
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv | |
# Add rbenv to the path: |
This installs a patched ruby 1.9.3-p327 with various performance improvements without a backported COW-friendly GC to make things happy on heroku, all courtesy of funny-falcon.
You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf
using homebrew.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Link Multiple Switches | |
description: | | |
## Link multiple switches together v1.0.1 | |
Select multiple switch entities to link their on/off state. If any selected switch entity is turned on or off, the other selected entities will be sent a matching on or off command. | |
Requires Home Assistant 2022.5.0 or newer. | |
Credit to @adchevrier for the initial blueprint: https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010 | |
Credit to @Hebus for this fantastic template: https://community.home-assistant.io/t/synchronize-the-on-off-state-of-2-entities/259010/38 |
OlderNewer