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 / 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 / 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 / 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 / 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 / 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 / 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 / asm_interp.rb
Created March 29, 2012 22:13
An AT&T assembly interpreter. It's not too great but you can do some simple math, as well as print out register values.
# registers
$reg = {eax: 0, ebx: 0, ecx: 0, edx: 0, esi:0, edi: 0, esp: 0, ebp: 0}
$Stack = []
$verbose = false
def gr(term); $reg[term]; end
def valid_reg(term); !$reg[term[1..-1].to_sym].nil?; end
def valid_imm(term); term[1..-1].to_i && term != "$0" ? true : false; end
def eval_asm(line)
@ox
ox / add_tag.java
Created April 5, 2012 02:09
AddTag for DOM Tree
public void addTag(String word, String tag) {
recursiveAddTag(root, word, tag);
}
private void recursiveAddTag(TagNode parent, String word, String tag) {
for (TagNode ptr=parent; ptr != null;ptr=ptr.sibling) {
String[] parts = ptr.tag.split(word+"[^\\s\\w]*",2);
if(parts.length > 1) {
System.out.println("operating on: " + java.util.Arrays.toString(parts));
if(ptr.tag.equals(word)) {
01: level1
02: WE5aVWRwYPhX
03: 1MkIE7hhtlXA
04: 1ZwMe9q1nDC9
package bar
import ( "fmt" )
// should be in a folder called foo
func Bar() {
fmt.Println("bats");
}