Skip to content

Instantly share code, notes, and snippets.

@ajesler
ajesler / group_before_and_after_shots.rb
Last active July 5, 2024 08:09
Takes a set of photos and gpx tracks, and sorts them into before and after shots of common locations
# A quick and dirty script to match a bunch of before and after photos of locations. The location of each
# photo is matched by reading timestamps out of a GPX file and finding the closest point in
# the track (time wise) to the time the photo was taken.
# It then groups the photos based on a distance in meters threshold (LocalityGrouper distance parameter).
# The more accurate your GPS and the more frequent your point entries in the GPX track, the
# better this will work.
#
# This script assumes your photos have different dates for the before and after. If this isn't
# the case, you'll need to change the logic used for calculating grouped_photos
#
@ajesler
ajesler / invoice.rb
Last active July 5, 2024 07:28
PDF Invoice generation script
#!/usr/bin/env ruby
# Usage:
# Save this to a file invoice.rb, and set the values from L#185 on to your needs.
# Then run
# $ ruby invoice.rb
require 'bundler/inline'
require "date"
@ajesler
ajesler / brief.txt
Last active July 5, 2024 07:11
Dev Share Problem
Take https://gist.github.com/ajesler/5c06c3bc5a9856f55472c617403a83d8 and solve the problem. Have a little fun with the solution, see what inefficient, ridiculous solutions you can come up with, push the bounds of your ruby knowledge a little. What constraints can you apply on how you solve it?
Full problem description at https://www.hackerrank.com/challenges/counting-valleys/problem?isFullScreen=true
Ideas: Can you do it in a single enumerable chain, can you write a program that generates the solver with meta programming, can you do it without using the letter e.
30m of problem solving in pairs, then 3m each to discuss what you tried to do, and what the highlights of your solution, working or otherwise. Don't worry if it doesn't work, its more about the journey and what you can learn.
@ajesler
ajesler / sock_market.rb
Last active June 16, 2022 03:40
A template for containing puzzle problems in a single file, including input data, and tests.
# frozen_string_literal: true
# The Sock Merchant
# from https://www.hackerrank.com/challenges/sock-merchant/problem
#
# Run the solver with the input after __END__
# $ ruby sock_merchant.rb
#
# Run the solver using a file as input
# $ ruby sock_merchant.rb test_input.txt
class Bottles
def song
verses(99, 0)
end
def verses(from, to)
(to..from).to_a.reverse.map { |n| verse(n) }.join("\n")
end
def verse(number)

Keybase proof

I hereby claim:

  • I am ajesler on github.
  • I am ajesler (https://keybase.io/ajesler) on keybase.
  • I have a public key whose fingerprint is 4150 5ABD 2E3B EB1E 32F7 71C9 6B40 4E03 2023 E686

To claim this, I am signing this object:

/*
A Photon sketch for detecting motion.
This sketch will fire an event when motion is detected, and when it is lost.
The motion timeout is done by the PIR sensor.
*/
const int LED = D7;
const int PIR1 = D4;
const int PIR2 = D5;
#!/usr/bin/env python
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
# Appends an allow CORS header for files served from a dir.
# Useful when you have an html page that makes requests to load json files from the same dir.
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
/*
A Photon sketch for detecting motion.
This sketch will fire an event when motion is detected, and when it is lost.
The motion timeout is done by the PIR sensor.
*/
const int LED = D7;
const int PIR1 = D4;
const int PIR2 = D5;