This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert ChatGPT conversations into markdown | |
# source: https://dev.to/gavi/convert-chatgpt-conversations-to-obsidian-markdown-format-p61 | |
# Improvements (tried to match original coding conventions) | |
# 2023.08.10: Fix bug accessing 'parts' in node['message']['content']['parts'] | |
# 2024.01.06: Updated get_conversation to handle non-string content parts, i.e. images (which are not currently included in the ChatGPT exports) | |
# 2024.01.20: Added link to conversation in ChatGTP using conversation_id, and also set time stamps correctly, esp. on macOS | |
import json | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
record.errors[attribute] << 'can''t equal name, username, or email' if [ record.name, record.username, record.email ].include?(value) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make sure we load our validators | |
config.autoload_paths += Dir["#{config.root}/lib/**/"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
# part of my User class, note the password => true, this tells Rails to call my custom validator | |
validates :password, :presence => true, | |
:password => true | |
attr_accessible :name, :username, :email, :password, :password_confirmation | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSS Fusion: combines multiple RSS feeds and prints out the last N sorted by date | |
require 'rss/1.0' | |
require 'rss/2.0' | |
require 'open-uri' | |
# sample feeds, replace with your own :-) | |
feeds = [ {:name => "Main", :url => "http://feeds.feedburner.com/Technoclippings"}, | |
{:name => "Art & Science", :url => "http://artscience.cyberclip.com/rss.xml"}, | |
{:name => "Tech", :url => "http://tech.cyberclip.com/rss.xml"}, | |
{:name => "Travel", :url => "http://travel.cyberclip.com/rss.xml"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# get count from file specified as input param | |
cnt = File.open(ARGV[0]).readline.strip.to_i | |
while cnt <= 15 do | |
puts "Hoppity\nHophop\nHoppity\nHoppity\nHophop\nHoppity\nHop\n" | |
cnt -= 15 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# get count from file specified as input param | |
cnt = File.open(ARGV[0]).readline.strip.to_i | |
# iterate... | |
# decided to minimize the number of mod operations by using a bit mask | |
1.upto(cnt).each do |i| | |
mask = i % 3 == 0 ? 1 : 0 | |
mask += i % 5 == 0 ? 2 : 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Calculates Mandelbrot equation for point (-0.75, x) where x -> 0 | |
# Amazingly the resulting iterations approximate pi | |
def mandel_iter (xp, yp, max) | |
x = y = 0.0 | |
n = 0 | |
while ((x*x + y*y) <= 4 and n < max) do | |
x , y , n = x*x - y*y + xp , 2*x*y + yp, n + 1 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#classify.rb - set id3 tags on mp3 files | |
require 'mp3info' #from http://ruby-mp3info.rubyforge.org/ | |
MUSICDNS = "<path to example.exe from MusicDNS>" | |
MUSICDIR = "<path to your music directory>" | |
def build_filename(fn) | |
"#{MUSICDIR + '/' + fn}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tinyproxy.rb | |
# just for the fun of it | |
require 'socket' | |
require 'http-access2' | |
def process_request(conn) | |
verb, uri, protocol = conn.gets.split | |
puts uri | |
http = HTTPAccess2::Client.new() |