Skip to content

Instantly share code, notes, and snippets.

View TeWu's full-sized avatar
💭
Loading...

Tomasz Więch TeWu

💭
Loading...
View GitHub Profile
@TeWu
TeWu / ev.rb
Created August 2, 2011 23:47 — forked from dkubb/ev.rb
Poor-man's Embedded Value
class User
include DataMapper::Resource
property :id, Serial
property :username, String, :required => true, :unique => true
property :address_street_address, String
property :address_location, String
property :address_subdivision, String
property :address_country, String
@TeWu
TeWu / gist:1234573
Last active February 2, 2022 20:23
TCP client and multithreaded server in 14 lines of Ruby code

TCP client and multithreaded server in 14 lines of Ruby code

Server:

require "socket"
server = TCPServer.open(2626)
loop do
	Thread.fork(server.accept) do |client| 
 client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*")
@TeWu
TeWu / gist:1285894
Created October 14, 2011 00:14
naive multithreaded catastrophic backtracking
p = /\A(aa|aab?)+\Z/
@counter = 0
s = ""
t = []
64.times { t << Thread.fork { puts "start" }; t.last.join }
while s.length < 200
i = s.length % t.size
t[i].join
t[i] = Thread.fork(s.dup) do |s|
@TeWu
TeWu / hashtable.rb
Last active June 2, 2017 12:07
Simple Hashtable implementation (hash collision resolution with open adressing)
class Hashtable
INITIAL_TABLE_SIZE = 32
Entry = Struct.new(:key, :value)
def initialize
@table = Array.new(INITIAL_TABLE_SIZE)
end
attr_accessor :table
@TeWu
TeWu / recursive_to_iterative.rb
Created September 8, 2012 14:16
Przekształcanie algorytmów rekurencyjnych w iteracyjne (recursive to iterative algorithm transformation)
#
# Przekształcanie algorytmów rekurencyjnych w iteracyjne
# na przykładzie znanych i kochanych algorytmów:
# BinarySearch i QuickSort ;)
#
#
# ======================== Binary Search Algorithm =================================
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}'
local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}'
local git_branch='$(git_prompt_info)%{$reset_color%}'
PROMPT="╭─${user_host} ${current_dir} ${git_branch}
╰─%B$%b "
RPS1="${return_code}"
@TeWu
TeWu / IBSim.scala
Last active August 29, 2015 14:11
100 Prisoners problem simulation
import scala.collection.immutable.TreeMap
import scala.util.Random
/* 100 prisoners problem - simulation of various strategies
* Decription at:
* - http://en.m.wikipedia.org/wiki/100_prisoners_problem
* - https://www.youtube.com/watch?v=eivGlBKlK6M
*/
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.battery_level_monitor_example"
android:versionCode="1"
android:versionName="0.0.1">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />