Skip to content

Instantly share code, notes, and snippets.

@tmikoss
tmikoss / Dockerfile
Created March 26, 2023 19:50
Homeassistant + HACS docker
FROM alpine:latest AS workbench
RUN apk --no-cache add curl libarchive-tools
FROM workbench AS tapo_control
RUN curl -L -o addon.zip https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/archive/refs/tags/4.2.4.zip
RUN mkdir -p addon
RUN bsdtar --strip-components=1 -C addon -xvf addon.zip
FROM workbench AS roborock
RUN curl -L -o addon.zip https://github.com/humbertogontijo/homeassistant-roborock/archive/refs/tags/0.0.28.zip
js_extend: false
translations:
- file: "app/javascript/i18n/translations.js"
+++ except: ["*.faker", "*.devise"]
RSpec::Matchers.define :finish_within do |timeout|
match do |block|
begin
Timeout.timeout(timeout) do
Benchmark.realtime{ block.call } <= timeout
end
rescue TimeoutError
false
end
end
@tmikoss
tmikoss / gist:4265939
Created December 12, 2012 07:56
Capistrano: work with current branch
function git-current-branch {
git branch 2>/dev/null | grep -e '^*' | sed -E 's/^\* (.+)$/\1 /'
}
function cap-current {
cap -s branch=git-current-branch $*
}
@tmikoss
tmikoss / named_submodules.rb
Created November 28, 2012 15:27
List named sub-modules of a module.
module NamedSubmodules
def named_submodules
constants.map{ |c| const_get c }.select{ |c| c.is_a?(Module) && c.const_defined?('SUBMODULE_NAME') }
end
def named_submodule_list
named_submodules.inject({}) do |hash, mod|
hash[mod.to_s] = mod.const_get('SUBMODULE_NAME')
hash
end
@tmikoss
tmikoss / log.rb
Created November 16, 2012 07:06
Capistrano recipes for remote log viewing
namespace :log do
desc "Search from log files on server"
task :grep, :roles => :app do
run "cd #{current_path}/log && grep #{ENV['str']} -B #{ENV['before'] || 5} -A #{ENV['after'] || 35} #{rails_env}.log*"
end
desc "Tail log files on servers"
task :tail, :roles => :app do
run "tail -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
puts "#{data}"
@tmikoss
tmikoss / gist:4030121
Created November 7, 2012 08:05
Rails 3 implementation of .none scope
module ActiveRecord
class Base
class << self
if respond_to? :none
puts "ActiveRecord::Base already has a method 'none'. Remove the implementation from #{__FILE__}"
else
# In Rails 4 this creates a noop query. Until then, use a query that never returns data.
def none
where '1=2'
end