Skip to content

Instantly share code, notes, and snippets.

View dmateos's full-sized avatar

Daniel Mateos dmateos

View GitHub Profile
<html>
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.pack.js">
</script>
<script>
$(document).ready(function() {
function debug(str) {
$("#debug").append(str + "<br/>");
};
require 'rubygems'
require 'em-websocket'
host = "0.0.0.0"
port = 8080
clients = {}
EventMachine::WebSocket.start(:host => host, :port => port) do |socket|
puts "new connection"
<html>
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.pack.js">
</script>
<script>
$(document).ready(function() {
function debug(str) {
$("#debug").append(str + "<br/>");
};
def qsort_partition(array, left, right, pivotindex)
pivotval = array[pivotindex]
storeindex = left
array[pivotindex], array[right] = array[right], array[pivotindex]
left.upto(right-1) do |i|
if array[i] < pivotval
array[i], array[storeindex] = array[storeindex], array[i]
storeindex += 1
end
#include <stdio.h>
#include <stdlib.h>
#define TESTARRAYSIZE 20
#define TESTVALMAX 100
void swap(int array[], int x, int y) {
int tmp = array[x];
array[x] = array[y];
array[y] = tmp;
1 def find_words_after array, word
2 list = []
3
4 array.each_with_index do |w, k|
5 if word == w
6 if list.index(array[k+1]).nil?
7 puts list
8 list << {array[k+1] => 0}
9 end
10 end
1 def find_words_after array, word
2 list = []
3
4 array.each_with_index do |w, k|
5 if word == w
6 if list.index(array[k+1]).nil?
7 puts list
8 list << {array[k+1] => 0}
9 end
10 end
text = File.read('text')
word_array = text.split
puts text
word_hash = {}
word_array.each { |word| word_hash[word] = [] }
word_hash.each do |wh_word, wv|
word_array.each do |p|
list = {}
def build_freq_table text
word_array = text.split
word_hash = {}
word_array.each { |word| word_hash[word] = [] }
word_hash.each do |wh_word, wh_value|
list = {}
word_array.each_with_index do |wa_word, index|
list[word_array[index+1]] += 1 if wh_word == wa_word and not list[word_array[index+1]].nil?
list[word_array[index+1]] = 1 if wh_word == wa_word and list[word_array[index+1]].nil?
#include <stdio.h>
#include <stdlib.h>
struct stack {
int val;
struct stack* next;
};
struct stack* push(struct stack* s, int val) {
struct stack *new = malloc(sizeof(*new));