Skip to content

Instantly share code, notes, and snippets.

View dfl's full-sized avatar

David Löwenfels dfl

View GitHub Profile
@dfl
dfl / sdparams.sh
Last active March 9, 2024 16:59
bash script to get stable diffusion parameters from an image file
#!/bin/bash
filetype=$(file -b --mime-type "$1")
if [[ "$(uname)" == "Darwin" ]]; then # MacOS
# Check if ImageMagick is installed
if ! command -v identify >/dev/null 2>&1; then
echo "ImageMagick is not installed. Installing..."
brew install imagemagick
fi
@dfl
dfl / shoulda_extensions.rb
Last active August 27, 2023 19:25
should_respond_with shoulda helper
# test helpers for integration testing written by David Lowenfels
# place in lib/internaut/shoulda_extensions.rb
require "rails-dom-testing" # for css_select method
## Example usage
module Internaut
module ShouldaExtensions
extend ActiveSupport::Concern
@dfl
dfl / kajabi-dl.rb
Last active December 7, 2023 19:56
ruby script for downloading kajabi course for archival purposes
# This script requires the nokogiri gem, and youtube-dl to be installed.
# It will fetch video, mp3, and text results.
# download cookies.txt using Chrome plugin "Get cookies.txt"
# download page source as course-page.html
quality = "iphone-360p" # to find quality options, use youtube-dl -v -F --cookies cookies.txt https://{KAJABI_COURSE}/categories/#####/posts/#####
cookies = "=cookies.txt"
course_url = "https://www.MYCOURSE.COM"
domain = course_url.split("/")[2]
@dfl
dfl / db.rake
Last active December 29, 2015 12:09 — forked from beatep/db.rake
require 'yaml'
require 'fileutils'
namespace :db do
desc "create the db/backup directory if it doesn't exist"
task :create_backup_dir do
FileUtils.mkdir_p backup_dir
end
@dfl
dfl / mysql.rake
Created April 12, 2011 04:34
rails rake tasks for dumping and reloading mysql databases
# mysql db backup and restore for rails
# by David Lowenfels <david@internautdesign.com> 4/2011
require 'yaml'
namespace :db do
def backup_prep
@directory = File.join(RAILS_ROOT, 'db', 'backup')
@db = YAML::load( File.open( File.join(RAILS_ROOT, 'config', 'database.yml') ) )[ RAILS_ENV ]
@db_params = "-u #{@db['username']} #{@db['database']}"
@dfl
dfl / factory.rb
Created March 8, 2011 06:42
ripped from the factories-and-workers gem
require 'digest/sha1'
module FactoriesAndWorkers
module Factory
def self.included( base )
def factory( kind, default_attrs, opts={}, &block )
FactoryBuilder.new( kind, default_attrs, opts, self, &block )
end
@dfl
dfl / active_record_callback_extensions.rb
Created August 11, 2010 16:16
mixin to selectively disable ActiveRecord callbacks
module Internaut
module ActiveRecord
module CallbackExtensions
def self.included(base) #:nodoc:
base.extend ClassMethods
base.class_eval do
class_inheritable_accessor :disabled_callbacks
self.disabled_callbacks = [] # set default to empty array
end
# example unit test context using should_change and should_not_change
context "Given a user" do
setup do
@user = create_user
end
context "when sent initials with a hyphen and lower case" do
setup do
@user.update_attributes!( :first_name => "Jason", :last_name => "happy-Klein" )