Jump to content

You wanted multiple picards right?


jean-luc

Recommended Posts

SO I made some changes to my server so that I can use different urls for the same imageset which means the browsers browsing will think it's two different images and therefor send two requests allowing me to send two different images... or more:

 

picard.1.pngpicard.2.pngpicard.3.pngpicard.4.png

picard.5.pngpicard.6.pngpicard.7.pngpicard.8.png

 

Here's hoping I don't crash my own server XD

 


 

wtf

 

Screenshot_20170227_180347.png

I don't visit as often as I used to. If you want me to see something, make sure to quote a post of mine or ping me @jean-luc

Link to comment
Share on other sites

May the source be with you:

=begin
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to 
=end
require 'sinatra'
require 'mime-types'

class Profile
 def initialize(files,type,weights=nil)
   @files = files
   @type = type
   @weights = weights
   @weights.map!{ |w| w.to_f / weights.reduce(:+) } unless weights.nil?
 end

 attr_reader :type

 def sample
   if @weights
     r = rand
     counter = 0
     index = -1
     while counter < r
       index += 1
       counter += @weights[index]
     end
     return @files[index]
   else
     @files.sample
   end
 end
 
 def sample_file
   File.open(self.sample)
 end
end

$mutex = Mutex.new

def update_profiles
 profiles = Dir['*'].find_all{|d| File.directory?(d)}
 profiles.map! do |name|
   weights = nil
   mime = ""
   pics = Dir.entries(name).map{|a| File.join(name,a)}.find_all do |entry|
     #puts "DEBUG: entry: #{entry}"
     #entry = File.join(name,entry)
     next false unless File.file?(entry)
     next false if entry.end_with?("~")
     if File.basename(entry) == "weights"
       weights = File.read(entry).split.map(&:to_i)
       false
     else
       mime = MIME::Types.type_for(entry).first
       if mime.nil?
         mime = "text/#{File.extname(entry).gsub('.','')}"
         puts "debug: mime was nil for #{entry}, using #{mime}"
       else
         mime = mime.simplified
       end
       true
     end
   end
   [name,Profile.new(pics,mime,weights)]
 end
 $profiles = Hash[profiles]
end

update_profiles

Thread.new do
 loop do
   sleep(1)
   $mutex.synchronize do
     update_profiles
   end
 end
end

get '/pp/:name' do |name|
 $mutex.synchronize do
   name = name.split(/\A([^\.]+)\.?[0-9]*(\.[a-zA-Z]{2,4})\Z/).join('')
   p = $profiles[name]
   next 404 if p.nil?
   content_type p.type
   chosen_one = p.sample
   puts "Picked #{chosen_one}"
   next File.open(chosen_one)
 end
end

I don't visit as often as I used to. If you want me to see something, make sure to quote a post of mine or ping me @jean-luc

Link to comment
Share on other sites

I've scrolled through some of the threads you've posted in multiple times. You still have the same image on each post.

 

Right, unfortunately I cannot make it use different urls for each post, I can only do it for images within a post.

I don't visit as often as I used to. If you want me to see something, make sure to quote a post of mine or ping me @jean-luc

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...