Skip to content

Instantly share code, notes, and snippets.

@lww
lww / index.js
Last active October 24, 2019 19:58
HB Plugin Sample
const APIWrapper = require('./APIWrapper')
const Service, Characteristic
module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory("switch-plugin", "MyAwesomeSwitch", mySwitch);
};
mySwitch.prototype = {
@lww
lww / gist:6244221
Last active December 21, 2015 03:39
new user with strong parameters
# routes.rb
get 'register', to: 'users#new'
get 'sign_in', to: 'sessions#new'
resources :users, only: [:create]
# users_controller.rb
def new
@user = User.new
end
@lww
lww / gist:5322388
Last active December 15, 2015 20:59
My Solutions for the ruby exercises, feel free to comment
arr = (1..10).to_a
# 1. Use the "each" method of Array to iterate over [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], and print out each value.
arr.each do |number|
puts number
end
# 2. Same as above, but only print out values greater than 5.
arr.each do |number|
puts number if number > 5
@lww
lww / gist:5321333
Created April 5, 2013 18:03
Calculator solution for whitespace
require "pry"
puts "Welcome to your calaculator!"
puts "What's the first #?"
num1 = gets.chomp
puts "What's the second number?"
num2 = gets.chomp