Skip to content

Instantly share code, notes, and snippets.

View paulclip's full-sized avatar

Paul Clip paulclip

View GitHub Profile
@paulclip
paulclip / gpt2mdconvert.py
Created January 23, 2024 21:05
Python script to convert ChatGPT exports into markdown files, suitable for importing into Obsidian et al
# 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
@paulclip
paulclip / password_validator.rb
Created February 21, 2011 01:31
Rails 3 Custom Validators
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
@paulclip
paulclip / application.rb
Created February 21, 2011 01:29
Rails 3 Custom Validators
# Make sure we load our validators
config.autoload_paths += Dir["#{config.root}/lib/**/"]
@paulclip
paulclip / User.rb
Created February 21, 2011 01:24
Rails 3 Custom Validators
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
@paulclip
paulclip / gist:785390
Created January 18, 2011 23:38
RSSFusion
# 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"},
@paulclip
paulclip / gist:759787
Created December 30, 2010 13:20
Hoppity Optimized
#!/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
@paulclip
paulclip / gist:759786
Created December 30, 2010 13:19
Hoppity Standard
#!/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
@paulclip
paulclip / gist:757187
Created December 28, 2010 13:00
Mandelbrot and Pi
#!/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
#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
# 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()