Skip to content

Instantly share code, notes, and snippets.

View technicalpickles's full-sized avatar

Josh Nichols technicalpickles

View GitHub Profile
@technicalpickles
technicalpickles / whyunosleep.rb
Created November 7, 2017 20:56
Find out what is keeping your Mac display on
#!/usr/bin/env ruby
assertions = {}
lines = `pmset -g assertions`.lines.map {|line| line.chomp }
lines.each do |line|
# pid 329(Slack): [0x00004c1d00058b13] 24:48:54 NoDisplaySleepAssertion named: "Electron"
if line =~ /pid (\d+)\((.*)\): \[.*\] (\d+:\d+:\d+) (\w+) named: \"(.*)\"/
pid = $1.to_i
application = $2
date = $3
assertion_type = $4
require 'bundler/setup'
require 'faraday'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
require 'pry'
conn = Faraday.new do |faraday|
faraday.adapter :typhoeus
end
@technicalpickles
technicalpickles / configuration.yaml
Created October 4, 2016 02:51
HomeAssistant group view with nested group
group:
living_room_lights:
name: Living Room Lights
entities:
- light.living_room_lamp
living_room:
name: Living Room
view: yes
entities:
import logging
from datetime import timedelta
from requests.exceptions import ConnectionError as ConnectError, \
HTTPError, Timeout
from homeassistant.components.sensor import DOMAIN
from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
require 'faraday'
require 'faraday_middleware'
module Icecast
class Admin < Faraday::Connection
class Error < RuntimeError
end
class AdminError < Error
end
@technicalpickles
technicalpickles / it.coffee
Created June 19, 2015 15:02
hubot script example with test
# Description:
# Get help from @yourorg/it for your information technology problems. Oh by the way.... Your Welcome.
#
# Commands:
# hubot it me <problem> - get help from @yourorg/it about your information technology <problem>
module.exports = (robot) ->
robot.respond /it(?: me)?(?: (.*))?/i, (msg) ->
problem = msg.match[1]
@technicalpickles
technicalpickles / inspector
Last active November 8, 2020 20:59
hubot with debugging
#!/bin/bash
set -e
for opt in $* ; do
case "$opt" in
--debug) hubot_debug="coffee --nodejs --debug";;
esac
done
@technicalpickles
technicalpickles / gist:a4581caa9378549dd59d
Created November 11, 2014 19:18
ruby retry example-
def flaky_code()
unless @flaky_code_works
@flaky_code_works = true
raise 'wtf'
end
puts "works eventually lol"
end
@technicalpickles
technicalpickles / gist:396a55d2c7198cd7090b
Created September 18, 2014 20:08
Rails ENV based HTTP auth
class PostsController < ApplicationController
if ENV['HTTP_AUTH_USERNAME'].present? && ENV['HTTP_AUTH_PASSWORD'].present?
http_basic_authenticate_with name: ENV['HTTP_AUTH_USERNAME'], password: ENV['HTTP_AUTH_PASSWORD']
def index
render plain: "Everyone can see me!"
end
end
@technicalpickles
technicalpickles / error.coffee
Created June 20, 2014 21:39
Simple hubot error handling
module.exports = (robot) ->
robot.error (err, msg) ->
robot.logger.error "#{err}\n#{err.stack}"
if msg?
msg.reply "#{err}\n#{err.stack}"