Skip to content

Instantly share code, notes, and snippets.

Peter Vojtek petervojtek

Block or report user

Report or block petervojtek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@petervojtek
petervojtek / HC-SR04.ino
Created Feb 13, 2014
HC-SR04 with power on and off to save power. Not working properly due to unknown reason. discussion here: http://forum.arduino.cc/index.php?topic=216079.0
View HC-SR04.ino
const int trigPin = 6;
const int echoPin = 7;
const int powerPin = 5;
const int ledPin = 13;
void setup() {
Serial.begin(9600);
pinMode(powerPin, OUTPUT);
pinMode(trigPin, OUTPUT);
@petervojtek
petervojtek / obce.rb
Last active Aug 29, 2015
zhlukovanie obci SR podla podobnosti nazvu (jedno pismenko sa moze lisit v ramci danej skupiny)
View obce.rb
# http://petervojtek.eu/wiki/Bike/2014-08-10Cyklookruh%C4%8Cekovce-%C4%8Celovce-%C4%8Cebovce
# encoding: utf-8
villages_full_names = File.read('obce.txt').split "\n"
#villages = ["Ďurkovce", "Hrkovce", "Markovce", "Mirkovce", "Širkovce", "Hokovce"]
villages = villages_full_names.collect{|v| v.sub(/ \/ .+/, '')} # Abrahámovce / okres Bardejov -> Abrahámovce
similar_villages = {}
View wma-to-mp3.rb
Dir.chdir ARGV[0]
wmas = Dir.glob("*.wma")
wmas.each do |wma|
wma = File.basename wma
mp3 = "#{wma.gsub(/[[:space:]]/,'').downcase[0..-4]}mp3"
puts "processing #{wma} to #{mp3}"
`avconv -i \"#{wma}\" -acodec libmp3lame -ab 128k #{mp3}`
end
`rm *.wma`
@petervojtek
petervojtek / zrsr.rb
Created Apr 28, 2015
Zivnostnensky register z Ruby (zrsr.sk)
View zrsr.rb
# kod nizsie vyhlada zivnostnikov ktori maju ako obec uvedene Malinovo
require 'uri'
require 'net/http'
uri = URI('http://www.zrsr.sk/zr_om.aspx')
res = Net::HTTP.get_response(uri)
require 'nokogiri'
doc = Nokogiri::HTML.parse res.body
View gist:599062
gist command didn't work at all without github.user config
@petervojtek
petervojtek / gist:4316754
Created Dec 17, 2012
Ruby Garbage Collector not garbage collecting as expected
View gist:4316754
# Ruby MRI 1.9.2 p136
class Person
def self.destructor name
proc{ puts "I AM DYING: #{name}"}
end
attr_reader :name
def initialize name
@petervojtek
petervojtek / mocp_rpi.rb
Created Jun 14, 2013
BerryClip Raspberry Pi + Music on Console (mocp)
View mocp_rpi.rb
require 'pi_piper'
include PiPiper
`su pi -c \"mocp -S\"`
red_led = PiPiper::Pin.new(:pin => 4, :direction => :out)
green_led = PiPiper::Pin.new(:pin => 11, :direction => :out)
red_led.off
green_led.off
after :pin => 7, :goes => :high do
View stepper_motor.rb
require 'rubygems'
require 'pi_piper'
include PiPiper
motor_sequence = [
[true, false,false,false],
[true, true, false,false],
[false,true, false,false],
[false,true, true, false],
[false,false,true, false],
View water_drop.rb
# sudo crontab -e
# 0 * * * * ruby /home/pi/Repositories/water_drop/src/water_drop.rb
puts "Water Drop: started"
unless File.new(__FILE__).flock(File::LOCK_EX | File::LOCK_NB)
puts "Water Drop: There is already an instance running, I quit"
exit 1
end
@petervojtek
petervojtek / air_pump.ino
Last active Dec 21, 2015
arduino air pump aquarium
View air_pump.ino
int motorSpeedPin = 11;
int motorOnPin = 10;
void setup()
{
pinMode(motorOnPin, OUTPUT);
pinMode(motorSpeedPin, OUTPUT);
digitalWrite(motorOnPin, 1);
}
You can’t perform that action at this time.