Skip to content

Instantly share code, notes, and snippets.

View technicalpickles's full-sized avatar

Josh Nichols technicalpickles

View GitHub Profile
@technicalpickles
technicalpickles / main.go
Last active February 23, 2024 16:50
lefthook stdin capture reproduction WIP for https://github.com/evilmartians/lefthook/issues/588
package main
import (
"context"
"io"
"os"
"os/exec"
"github.com/creack/pty"
)
@technicalpickles
technicalpickles / benchmark.rb
Last active September 11, 2023 21:25
Bundler::Settings#[] benchmark, see https://github.com/rubygems/rubygems/pull/6923
require "benchmark/ips"
require "benchmark/memory"
require 'bundler'
class Bundler::Settings
def original(name)
key = key_for(name)
value = configs.values.map {|config| config[key] }.compact.first
converted_value(value, name)
@technicalpickles
technicalpickles / benchmark.rb
Created August 24, 2023 13:30
AbstractController::Base#action_methods benchmark
# frozen_string_literal: true
require 'action_controller'
require 'benchmark/ips'
require 'benchmark/memory'
puts "ActionPack.version = #{ActionPack.version}"
module Actions
def foo
end
@technicalpickles
technicalpickles / benchmark.rb
Last active August 15, 2023 17:13
Benchmarking Net::HTTPHeader#capitalize
# frozen_string_literal: true
require 'benchmark/ips'
require 'benchmark/memory'
def original(name)
name.to_s.split(/-/).map {|s| s.capitalize }.join('-')
end
def string(name)
name.to_s.split('-').map {|s| s.capitalize }.join('-')
@technicalpickles
technicalpickles / benchmark.rb
Created August 8, 2023 21:43
Ruby performance: caller vs caller(1, n) vs stack_frame gem
require 'benchmark/ips'
require 'stack_frames'
STACK_FRAMES_BUFFER = StackFrames::Buffer.new(500)
def recurse(n, &block)
if n > 0
recurse(n - 1, &block)
else
yield
# Using Sonic-Pi
samps = "/Users/technicalpickles/Dropbox/sonicpi-samples/"
##| use_bpm 120
define :mario_waha do |options={}|
options ||= {}
sample samps, "mlpit_mario_waha.wav", options
end
@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