Skip to content

Instantly share code, notes, and snippets.

View ox's full-sized avatar
👹
what is this, AIM?

Artem Titoulenko ox

👹
what is this, AIM?
View GitHub Profile
@ox
ox / 1L.c
Created February 12, 2010 15:52
FULL Brainfuck implimentation in response to Marc-André's Gist: http://gist.github.com/302316;
// Brainfuck, full implimentation, idea by Marc-André Cournoyer. this is turing complete.
// the bracket code was made by a friend, zli5t. my implementations were way too complex. or wrong.
// compile: gcc 1L.c
// example:
// ./a.out ++.
// expanded:
// incriment reg[0] by 1
// incriment reg[0] by 1
// print out reg[0]
// outputs: 2
@ox
ox / Ruby Formula Solver.rb
Created February 8, 2011 05:04
This is a little something I cooked up over a day or two. It solves physics problems easily when solving for a single variable. It's not Wolfram|Alpha or Maple, but it's nifty in a bind. Hope it's useful!
lim = lambda{|f,h|
y=h
1.upto(1.0/0) { |p| ##to infinity
x=h+(1.0/10)**p ##increase how close x is to h 1.0,0.1,0.001 etc..
fx=f[x] ##get f(x)
break if y==fx ##if we start getting the same val, stop
y=fx ##store the last val
}
y ##return where we stopped
}
@ox
ox / C.rb
Created March 6, 2011 23:09
A simple time clocker for your next project.
#!/usr/bin/ruby
# Version (0.78)
# Created by Artem Titoulenko (artem.titoulenko@gmail.com)
# clock in application. I'm tired of counting.
# C.rb -- Time keeping script.
# Call with no params to clock in/out
# Params:
# ? : are you clocked in? check
# log : peek at the work log
@ox
ox / dragon_curve.rb
Created March 25, 2011 03:04
A simple dragon curve algorithm
# Dragon Curve algorithm
# source: http://en.wikipedia.org/wiki/Dragon_curve
# Use: ruby dragon_curve.rb [number of iterations]
str = "R"
ARGV[0].to_i.times do
nstr = str.reverse
for i in 0..nstr.length
@ox
ox / gist:1094317
Created July 20, 2011 04:11
JS ASync for MarkBao
array = ['test', 'of', 'file'];
array2 = ['another', 'array'];
// just calls the callback and passes in this item
String.prototype.toArray = function(callback) {
callback(null, this);
};
// test
@ox
ox / todo.rb
Created August 13, 2011 16:45
A small todo program I wrote in a sitting. Incredibly simple.
#!/usr/bin/env ruby
# coding: utf-8
#this is a normal todo prog which saves your todos in a local file called .todo
#./todo --help
#todo.rb usage:
# todo.rb list all active tasks
# todo.rb <task> create a task described by <task>
# todo.rb -r <string> deletes all tasks matching <string>
@ox
ox / log_tester.rb
Created August 20, 2011 06:49
Networked Logging in Ruby Using ZeroMQ
require 'zmq'
class Logger
def initialize
@context = ZMQ::Context.new
@pub = @context.socket ZMQ::PUB
@pub.bind "ipc://logger:general"
end
def log(message)
@ox
ox / get_electro.rb
Created September 8, 2011 02:51
Grab the Latest Electro off Console.fm
['open-uri', 'hpricot'].each(&method(:require))
eval("Dir.mkdir %{s}; Dir.chdir %{s}" % {s:"\"electro-house\""})
(open("http://console.fm/electro-house") { |html| Hpricot(html) }).search("a[@href*=media.console.fm/tracks]").each do |a|
File.new("#{a.inner_html.gsub!(/[\s&\/',]/, "_")}.mp3", "w").puts(open(a.get_attribute('href')).read); puts "#{a.inner_html}"
end
@ox
ox / consolefm_spotify_playlist.rb
Created September 9, 2011 15:18
Grab the latest Electro-House from Console.fm and make a spotify playlist out of it. Fuck downloading. It's naive.
['open-uri', 'hpricot', 'meta-spotify'].each(&method(:require))
playlist = []
(open("http://console.fm/electro-house") { |html| Hpricot(html) }).search("a[@href*=media.console.fm/tracks]").each do |a|
m = a.inner_html.match(/(.*?) by (.*?)$/)
song = MetaSpotify::Track.search(m[1])[:tracks].first
unless song == nil
puts "\e[32m#{song.name} by #{song.artists.first.name}\e[0m, #{song.uri} "
playlist << song.uri
else
puts "\e[31mX\e[0m \"#{a.inner_html}\""
@ox
ox / consolefm.rb
Created September 10, 2011 16:18
Pick any genre (passed as arg) and get back a directory full of mp3 with proper ID3 tags from console.fm. Enjoy
#!/usr/bin/env ruby
require 'open-uri'
require 'hpricot'
class ID3Tag
attr_accessor :title, :artist, :album, :year, :comment, :genre, :track
def initialize
@title = @artist = @album = @comment = "\0" * 30
@year = "\0\0\0\0"