Skip to content

Instantly share code, notes, and snippets.

View nebs's full-sized avatar

Nebojsa Petrovic nebs

View GitHub Profile
@nebs
nebs / thumbdown.rb
Created July 24, 2016 18:53
Ruby script for downloading multiple YouTube video thumbnail images.
# This gist is used to batch download thumbnails for YouTube videos.
# You must create a txt file that includes a list of video IDs (one per line).
#
# To get the IDs for your videos:
# 1. Goto: https://www.youtube.com/my_videos
# 2. Open a JS Console
# 3. Run: var o="";var v=document.getElementsByClassName("vm-video-title-container");for(var i in v){o+=v[i].id.replace("title_","")+"\n";}
# 4. The variable "o" contains a string with all the IDs, type "o" to print it.
# 5. Copy the IDs into a text file (one per line)
#
@nebs
nebs / arduino-16-ch-analog-mux.cpp
Last active November 5, 2022 15:52
Arduino 16-Channel Analog Multiplexer Reading
/*
This code relies on the fact that PORTB on the ATMega328 chip has consecutive pins
which we can take advantage of to set the channel on the mux.
This code has been tested with Sparkfun's 16-ch mux (https://www.sparkfun.com/products/9056).
*/
#define MUX_CH_COUNT 16 // Reduce this number if you use less channels
#define PIN_D_MUX_S0 8 // bit 7 of PORTB
#define PIN_D_MUX_S1 9 // bit 6 of PORTB
@nebs
nebs / arduino-random-seed-mem.cpp
Last active November 3, 2022 16:59
Arduino random seed with EEPROM
/*
Arduino's random() function repeats when the program resets.
The typical solution is to seed it with a floating analog pin reading.
The problem with that is that the analog pin is not really random either
so you still end up with sequences that repeat fairly frequently. It also
requires you to give up an analog pin.
This gist attempts to solve these problems by storing the previous seed
in EEPROM and incrementing it each time the program resets.
@nebs
nebs / find_unused_ruby_functions.sh
Last active January 1, 2016 01:59
Bash script to list ruby functions that are potentially not used. It relies on 'ack' and is currently pretty slow to execute for large projects.
#!/bin/bash
BOIFS=$IFS
IFS=$'\n'
echo "Possible unused functions:"
for line in `ack -h --ruby 'def .*' | sed 's/ //g'`; do
function_name=${line#def*}
function_name=${function_name#self.*}
function_name=${function_name%(*}
num_matches=`ack -c -h $function_name | sed 's/ //g'`
if [ "$num_matches" -lt 2 ]