Skip to content

Instantly share code, notes, and snippets.

class Song < Sequel::Model
plugin :validation_helpers
self.raise_on_save_failure
def validate
super
validates_presence [:title, :length, :released_on, :lyrics]
end
end
# Attempt to use rack/reverse proxy to serve up files upon request that exist outside site root
# The full address for the files /vagrant/TestRails/Music/various-subdirectories
# You can see below the Sinatra route which uses the splat.
# I'm confused as to what should be in the reverse_proxy line, having tried a number of different variations
# Sinatra route
get '/file/*' do
slim :search_results
end
@stuartambient
stuartambient / gist:3ece8d44e060f46aa8af44a8505cfd32
Created November 1, 2017 22:36
Nginx and Thin with Sinatra app
# netstat -anp
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ] DGRAM 20453 2767/systemd /run/user/1000/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 20454 2767/systemd /run/user/1000/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 9974 1/init /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 17042 1294/postgres /var/run/postgresql/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 9780 1/init /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 9790 1/init /run/systemd/fsck.progress
### i need to add another condition in on the Dir.entries, so that directories do not print out
### having no luck with File.stat(x)file? or File.file?....etc
get '/entry' do
list = Dir["/vagrant/TestRails/RubyPractice/RailsGirls/**/*"]
list.each do |dir|
if File.directory?(dir)
puts "Directory: #{dir}\n"
Dir.entries(dir).reject { |x| p "Entry: #{x}" if x =~ /^[^.].*$/ }
end
@stuartambient
stuartambient / gist:d04fc61c5747918541da1f37beda25f9
Created November 18, 2017 01:49
Inserting the album_sub_folder id conditional statement
# is it possible to have an if statement in the insert
# dataset and map works in bin/sequel so that is not the problem
check_ids = DB.fetch("SELECT * FROM album_sub_folders WHERE album_id = {@album_id}")
.....
.....
MUSIC_FILES.insert(file_name: File.basename(entry),
album_id: @album_id,
album_sub_folder_id: @asf_id if check_ids.map.count > 0,
- num_links = @albums.page_count
- link_first_part = %q[<li class="page-item"><a class="page-link" href="#">]
- link_second_part = %q[</a></li>]
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
- num_links.times do |i|
- i = 1
# route -
get '/pag' do
@all_album_links = paginate
@pages = {}
@all_album_links.each_slice(10).with_index do |x,i|
@pages.store("page #{i+1 }", "#{x}")
end
slim :pag
#end
end
@stuartambient
stuartambient / myPinkTruck.js
Created November 4, 2019 01:08 — forked from blogscot/myPinkTruck.js
Factory Pattern examples using ES6 syntax
class Car {
constructor(doors = 4, state = "brand new", color = "silver") {
this.doors = doors
this.state = state
this.color = color
}
}
class Truck {
@stuartambient
stuartambient / image.md
Created September 17, 2020 16:10 — forked from prof3ssorSt3v3/image.md
Layered background image effects and clipping
@stuartambient
stuartambient / challenge-3.4.js
Created November 18, 2020 02:12
NodeJS Design Patterns (third edition) challenges
const { EventEmitter } = require('events');
const ticker = (num, cb) => {
const emitter = new EventEmitter();
const counters = { timePassed: 0, count: 0 };
const timestamp = () => {
const time = Date.now();
return time % 5 === 0;