Skip to content

Instantly share code, notes, and snippets.

@chischaschos
chischaschos / bla_test.go
Last active August 29, 2015 14:06
Examples about how to do basic things in Go
package main
import (
"fmt"
"io/ioutil"
"os"
"./mypackage"
)
// The Bla1 example tests if the output matches
@chischaschos
chischaschos / combinations_calculator.rb
Last active August 29, 2015 14:04
Given an array of N numbers select all the possible groups of size 1..N that may be selected
def word_combinations(words, original_set_size = words.count, start_index = 0, end_index = words.count - 1, combinations = 1)
words[start_index..end_index].each do |combination|
words[0..original_set_size - 1].each do |original_combination|
unless combination.include?(original_combination.first)
new_combination = (combination + original_combination).sort
unless words.include?(new_combination)
words << new_combination
end
#import "Bob.h"
@implementation Bob
- (NSString *) hey: (NSString *) message {
if ([self isEmpty:message]) {
return @"Fine, be that way.";
} else if ([self isScreaming:message]) {
def update_hto_state
Rails.logger.info "Here we go"
if hto?
determine_hto_state
end
update_attributes_without_callbacks(hto_state: hto_state)
if hto_state_changed?
@chischaschos
chischaschos / README.md
Last active August 29, 2015 13:56
Movement broadcasting Project

Descripcion

  • Un sitio web expone una url publicamente.
  • Uno o mas usuarios pueden entrar a esa url publica.
  • Al entrar a esa url el browser muestra un circulo.
  • Cuando alguna de las teclas arriba, abajo, derecha o izquierda es presionada el circulo se mueve en la direccion indicada por la tecla presionada.
  • Cualquier movimiento de el circulo debera ser visto en las terminales de los clientes en tiempo real.
  • Uno o mas clientes pueden conectarse por linea de comando al sitio para ver en tiempo real como se mueve el circulo, cualquier movimiento de el circulo debe reflejarse en la terminal de el cliente.
  • La terminal de el cliente dibujara todos los circulos de todos los usuarios que se conecten al sitio y podra monitorear los movmientos de los circulos en tiempo real.
  • En cada sitio web de cada usuario moviendo un circulo debera poder ver cada uno de los otros circulos de los otros sitios web.
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Before;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
require 'ruby-prof'
def prime(n)
limit = n
numbers = Array.new(n + 1) { true }
start = 2
primes = []
loop do
numbers[start] && primes << start
require 'minitest/autorun'
SortSnail = -> (elements, result = []) {
return result if elements.empty?
bottom_limit = 0
top_limit = elements.count - 1
loop do
result.concat elements[bottom_limit][bottom_limit..top_limit]
@chischaschos
chischaschos / .ruby-version
Last active December 27, 2015 03:29
Exercises
2.0.0-p247
@chischaschos
chischaschos / shortest_path_spec.rb
Created October 29, 2013 22:26
dijkstra shortest path in ruby
require 'spec_helper'
SP = ->(graph, from_node, to_node, nodes = Hash.new(0), visited = [], i = 0) {
return nodes[from_node] if from_node == to_node
neighbours = graph[from_node].reject {|k, v| visited.include?(k) }
neighbours.each do |k, v|
if nodes[k] == 0 || nodes[from_node] + v < nodes[k]
nodes[k] = nodes[from_node] + v