08. September 2020

Fibonacci Spheres in Blender

I’ve been messing about with blender a bit since the pandemic started. I originally thought I could use it for visualizing data, which is certainly true, but I’ve found more that I’ve been getting in blender-world. I was watching a “coding adevntures” video over the weekend where the author described using fibonacci spheres as a way of evenly distibuting points on a sphere. But I couldn’t find an easy way to do this in blender.

So I made an extension. It’s mostly cobbled together from code snippets I found on-line. You can check it out on my git hub.

10. August 2020

Archiving photos from iOS to a network drive.

I wrote a while back about a script I wrote to run on my android phone that would sort and archive any photos I had on the device into dated folders I have on a network drive. Privacy and de-googling concerns led me to get an iphone when the time came to upgrade (essential, my old phone’s manufacturer shut down, and faced with an aging battery and a looming lack of support I decided to upgrade). This left me with a problem, how would I sort my images into my archive?

<span class=”more>

I’ve found it a bit harder to do fun hacks like the photo sorting hack on iOs as compared to android. My new work flow is:

  1. import (and delete) everything into i photo.
  2. export everything from there to a folder on my laptop.
  3. run this script:
require 'set'

`which exiftool || brew install exiftool`

class Copier

    def initialize(path)
        @path = path
        @created_folders = [].to_set
        @path = ''
        @userhost = 'network-host'
        @destpath = '/mnt/big-disk/photos'
    end

    def get_date(file)
        # some say Modified, other Modification.
        mod_date = `exiftool "#{file}" | grep 'Modif'`
        mod_date = mod_date.split("\n")[0] # first line
                        .split(" : ")[1] # the date time part
                        .split(" ")[0] # the date part
        mod_date.split(':')
    end

    def create_folder_if_need_be(date)
        year, month, day = date
        unless @created_folders.include?(date)
            puts "creating folder for #{date.join('-')}"
            `ssh #{@userhost} "mkdir #{@destpath}/#{year}" 2> /dev/null`
            `ssh #{@userhost} "mkdir #{@destpath}/#{year}/#{month}" 2> /dev/null`
            `ssh #{@userhost} "mkdir #{@destpath}/#{year}/#{month}/#{day}" 2> /dev/null`
            @created_folders << date
        end
    end

    def transfer_file_to_dated_folder(file, date)
        year, month, day = date
        `scp "#{file}" #{@userhost}:#{@destpath}/#{year}/#{month}/#{day}`
        puts "transferred #{file}"
    end

    def delete_local_file(file)
        `rm "#{file}"`
    end
end

path = "./photos/"
files = Dir["#{path}*"].sort_by(&:downcase)
c = Copier.new(path)
files.each do |file|
    date = c.get_date(file)
    c.create_folder_if_need_be(date)
    c.transfer_file_to_dated_folder(file, date)
    c.delete_local_file(file)
end

Looking at this now, it would be great to move the core of the files.each block into the class, and read the path and host from argv but it works so I’m happy with it.

21. October 2019

Uploading and sorting photos from android over sftp using termux.

I was super excited to find that I can install bash on my phone, then scp and ruby. It opens up a lot of possibility of what a phone should really be able to do. Too often I feel constrained by limited options in apps.

An example of this is taking old photos and putting them into my long term storage on my home computer. I backup to google photos, but I like to keep a local copy too. My old workflow for organizing files was to either use usb or “andftp” app on my android to get the files onto my machine, then sort them roughly by date into folders for ease of retrieval. Both of these methods are time consuming and don’t give the best result.

Here is my new work flow…

userhost = 'someguy@192.168.0.100'
destpath = '/mnt/big/camera'

['PIC', 'VID'].each do |type|
  transer_files(type)
end

def transfer_files(type)
  fs = ` ls storage/dcim/camera/#{t}* `.split("\n")

  prefixess = fs.map {|f| f.gsub(/.+#{t}_/, '').gsub(/_.+/,'')}.uniq

  years = prefixes.map{|p| p.slice(0,4)}.uniq

  prefixes.each do |p|
    handle_date_prefix(p)
  end
end

def handle_date_prefix(p)
  year = p.slice(0,4)

  mth = p.slice(4,2)
  day = p.slice(6,2)


  prefs.each do |p|
    transfer(year, mth, day)
  end
end

def transfer(year, mth, day)
 `ssh #{userhost} "mkdir #{destpath}/#{year}" `
 `ssh #{userhost} "mkdir #{destpath}/#{year}/#{mth}" `
 `ssh #{userhost} "mkdir #{destpath}/#{year}/#{mth}/#{day}" `

  c= `scp storage/dcim/camera/#{t}_#{p}* #{user_host}:#{destpath}m/#{year}/#{mth}/#{day} && rm storage/dcim/camera/#{t}_#{p}*`
  puts c
end

This nicely organizes all my files by date and clears out the space on my phone.

19. September 2018

Deep Learning Fundamentals

Here’s a talk I gave at work that gives a run-down of some fundamental concepts in deep learning, and I finished the talk with an example of a convolutional neural network in keras.

more