Skip to content

Instantly share code, notes, and snippets.

@unixcharles
unixcharles / TH1123ZB-G2.md
Last active March 20, 2024 18:38
Sinope TH1123ZB-G2 and Home Assistant + zigbee2mqtt

Keep information on the TH1123ZB-G2 screen up to date with Home Assistant and z2m.

Should work with other sinope thermostat like the TH1124ZB.

  • You need to manually push outdoor temperature.
  • Time generally work without this but it will go blank randomly or out of sync at some point (won't change for DST for example).
@unixcharles
unixcharles / nginx.conf
Last active January 18, 2024 12:21
nginx config for http/https proxy to localhost:3000
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
@unixcharles
unixcharles / Ohhh noes.txt
Created September 19, 2011 14:20
OSX libxml2 error fix
Look like brew libxml2 and the one bundled with osx are fighting
/Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle: dlsym(0x7ffb44ee7880, Init_libxml_ruby): symbol not found - /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle (LoadError)
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/libxml-ruby-1.1.4/lib/libxml.rb:9
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `require'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
from /Users/unixcharles/.rvm/gems/ruby-1.8.7-p352/gems/bundler-1.0.1
@unixcharles
unixcharles / gilded_rose.rb
Last active June 23, 2021 14:46
guilded_rose_kata
class ItemUpdater
class AgedBrie < ItemUpdater
def value_change
-super
end
end
class BackstagePass < ItemUpdater
def value_change
case sell_in
@unixcharles
unixcharles / hash_object.rb
Created November 15, 2018 20:41
Hash Driven Development
class HashObject
def []=(method_name, implementation)
define_singleton_method(method_name, &implementation)
end
def [](method_name)
if method(method_name).arity == 0
method(method_name).call
else
method(method_name).curry
@unixcharles
unixcharles / problem.rb
Created October 29, 2012 11:33
DelegateClass and "superclass mismatch for class" errors
require 'delegate'
class Klass < DelegateClass(String)
# ...
end
class Klass < DelegateClass(String)
# Re-open the class
end
# => TypeError: superclass mismatch for class Klass
@unixcharles
unixcharles / rate_limiter.rb
Created May 2, 2017 19:29
30 lines rate limited
# USAGE:
# rate_limiter = RateLimiter.new('throttle_key', limit: 5, ttl: 1.hour)
# rate_limiter.throttled { not_too_often }
#
class RateLimiter
attr_reader :topic, :limit, :ttl, :cache
def initialize(topic:, limit:, ttl:, cache: default_cache)
@topic, @limit, @ttl, @cache = topic, limit, ttl, cache
end
@unixcharles
unixcharles / heroku_env.rb
Created September 12, 2012 11:29
Import heroku env
#!/usr/bin/env ruby -rubygems
reject_keys = %w(PATH STACK URL APP_NAME LOG_LEVEL)
reject_keys += %w(RACK_ENV RAILS_ENV NODE_ENV)
reject_keys += %w(COMMIT_HASH CONSOLE_AUTH LANG LAST_GIT_BY)
reject_keys += %w(REDISTOGO NEW_RELIC DATABASE MONGOHQ MEMCACHE SENDGRID)
reject_keys += (ENV['REJECT_ENV_KEYS'].nil? ? [] : ENV['REJECT_ENV_KEYS'].split(','))
keys_regexp = %r/#{reject_keys.join('|')}/i
configuration = `heroku config`.split("\n").inject({}) do |hash, line|
@unixcharles
unixcharles / redis_clean.rb
Created August 23, 2012 14:21
Clean up redis queue
queue_name = 'queue:queue_name'
len = Resque.redis.llen(queue_name)
deletion = Resque.redis.lrange(queue_name,0, len).select do |entry|
JSON.parse(entry)['args'][0] == "some_criterial" rescue nil
end
deletion.each do |entry|
puts entry
puts Resque.redis.lrem queue_name, -1, entry
@unixcharles
unixcharles / creditcard.coffee
Created May 11, 2012 13:41 — forked from masylum/creditcard.coffee
Credit Card number validation in Coffee Script
# Ported from https://github.com/jzaefferer/jquery-validation/blob/master/jquery.validate.js
creditcard = (value)->
# accept only spaces, digits and dashes
return unless /[^0-9 \-]+/.test(value)
nCheck = nDigit = 0
bEven = false
checkDigit = (n) ->