Skip to content

Instantly share code, notes, and snippets.

@ajesler
ajesler / brief.txt
Last active June 17, 2022 03:57
Hatch 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;

Android Bluetooth Debugging

  • In developer options, turn on "Enable Bluetooth HCI snoop log". Will create a log at "/sdcard/btsnoop_hci.log"
  • To download the file, "adb pull /sdcard/btsnoop_hci.log"
  • To delete the file, "adb shell rm /sdcard/btsnoop_hci.log"

Open the file in Wireshark to see bluetooth packets wireshark -r btsnoop_hci.log

@ajesler
ajesler / bscco.rb
Last active September 1, 2016 07:47
# Caculate the BSCCO checksum for a file
# Usage: `$ ruby bscoo.rb your_file.txt`
# Based on the algorithm description in https://www.elexon.co.uk/wp-content/uploads/2013/11/bscp533_appx_a_v17.0.pdf
def bscco(file)
lines_except_last = File.read(file).lines[0..-2]
lines_as_bytes = lines_except_last
.map(&:chomp)
.map(&:bytes)
.map do |line_bytes|