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 / prob2.s
Created March 29, 2012 15:33 — forked from Codonaut/prob2.s
Tested to work right
.text
.globl
getCharAsInt:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl 12(%ebp), %edx
addl %edx, %eax
movb (%eax), %al
movsbl %al, %eax
@ox
ox / max.y86.asm
Created March 28, 2012 17:17
The Y86 version of the max(int numbers[], int len) function. Finds the greatest number in an array of ints. Comments are... non-standard.
.text
.globl max
max:
pushl %ebp
movl %esp, %ebp
mrmovl 8(%esp), %ecx
rrmovl %ecx, %eax #; pointer to numbers[]
mrmovl (%ecx), %ecx #; ecx holds greatest encountered
#; number
@ox
ox / max.asm
Created March 28, 2012 17:16
A function that is passed in an array of ints and the length of the array and tells you the greatest number in the array. eg: max(int numbers[], int len). Built on for i386, on a Mac, so you may need to change the labels (remove underscore), and the comme
.text
.globl _max
_max:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx #; assume first number is the greatest
movl %ecx, %eax #; eax points to the beggining of numbers[]
movl (%ecx), %ecx #; %ecx stores the highest number found
movl 12(%ebp), %edx #; len
@ox
ox / stream_pty.rb
Created March 19, 2012 02:27
A sinatra prototype that will run a pty session on the machine and show you a streamed response out to the web.
require 'sinatra'
require 'pty'
get '/' do
"<form action='/' method='POST'><input type='text' name='command'><input type='submit' value='run'></form>"
end
post '/' do
stream do |out|
out << "<html><body><pre>"
@ox
ox / ruby_benchmarker.rb
Created March 18, 2012 19:15
ruby_benchmarker for pissing contest
require 'sinatra'
require 'sequel'
# $ gem install thin mysql sequel
# the mysql gem is a MASSIVE pain in the ass, would rather
# use something saner like Postgres or Mongo or Redis
# thin is required, WEBRick is terrible
set :server, :thin
get '/' do
@ox
ox / sinatra_autoapi.rb
Created March 15, 2012 03:28
Sinatra AutoAPI generator in the making
require 'sinatra'
require 'sinatra/namespace'
require 'mongoid'
ENV["RACK_ENV"] ||= "development"
Mongoid.load!("mongoid.yml")
class Note
include Mongoid::Document
field :body, type: String
@ox
ox / rack_router.rb
Created March 6, 2012 18:52
A rack application that allows for some rudimentary routing using procs
class Router
attr_accessor :routes
def initialize
@routes = {}
end
def add_route(path, &block)
@routes[path] = block
end
@ox
ox / config.ru
Created March 4, 2012 08:14
Flea web server using Rack and my own flea fork
require 'rack'
require 'flea'
interpreter = Flea::Interpreter.new
run Proc.new { |env|
interpreter.run(File.read(File.new("server.scm")))
a = interpreter.evaluate([:call, env]).map! {|x|
interpreter.evaluate(x)
}
@ox
ox / symmetric_tree.rb
Created February 10, 2012 17:48
A function which, when given a root node, will determine if the tree is symmetric. AKA Breadth-first search
#tell whether the tree is visually symmetric (it is)
class Node
attr_reader :value, :left, :right
def initialize(value, left, right)
@value, @left, @right = value, left, right
end
#added in to see output
def to_s; @value.to_s; end
def inspect; @value.to_s; end
@ox
ox / main.c
Created January 21, 2012 15:11
sorting C structs, an example
typedef struct stump {
char * name;
int data;
} stump;
typedef struct container {
stump ** node_array;
} container;
int compare_stumps(const void *a, const void *b) {