Skip to content

Instantly share code, notes, and snippets.

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

Tomasz Więch TeWu

💭
Loading...
View GitHub Profile
require 'benchmark'
NA = 1000000
N = 1000
ARR = Array.new(NA) { rand }.freeze
Benchmark.bm do |x|
@TeWu
TeWu / _kRPC-rb Benchmarks & Checks
Last active November 28, 2016 16:55
kRPC-rb: Benchmark message hashing
kRPC Benchmarks & Checks
@TeWu
TeWu / semi_solution_notes.rb
Last active October 7, 2016 14:26
Puzzling: Hey, they are all under 4
#
# http://puzzling.stackexchange.com/questions/32438/hey-they-are-all-under-4
#
require 'active_support/core_ext/array'
c = "222123013102101232202311300000113113"
def decode(base,digits)
digits.reverse.inject([0,[]]) {|a,e| [a[0]+1, a[1] + [e*base**a[0]]]}[1].inject(0, :+)
@TeWu
TeWu / boxes.rb
Last active October 4, 2016 13:05
The prisoner boxes riddle solution simulation
#
# https://www.youtube.com/watch?v=vIdStMTgNl0
#
$SUCCESS = 0
$M = 1_000_000
$N = 10
puts Time.now
@TeWu
TeWu / version_01.rb
Last active September 16, 2016 08:57
Refactor or not to refactor - that is the question: Whether 'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune. Or to take arms against a sea of troubles. And by opposing end them.
def prev_photo_url(album, photo, **options)
prev_photo_id = album.prev_photo_id(photo)
album_photo_url album, prev_photo_id, options if prev_photo_id
end
def prev_photo_path (album, photo, **options)
prev_photo_url(album, photo, {only_path: true}.merge!(options))
end
def next_photo_url(album, photo, **options)
next_photo_id = album.next_photo_id(photo)
@TeWu
TeWu / HalfBirthdate.scala
Last active September 12, 2017 08:17
Half-BirthDate Calculator (halfbirthday)
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
object HalfBirthdate {
val date_2000_02_29: LocalDateTime = LocalDateTime.parse("2000-02-29T00:00:00")
case class HalfBirthdate(earlierHalfBirthDate: LocalDateTime, laterHalfBirthDate: LocalDateTime) {
def show() {
println("Earlier half-BirthDate: " + format(earlierHalfBirthDate))
@TeWu
TeWu / _spinner.html.erb
Last active August 8, 2016 21:22
CSS Animated Spinner (in Rails)
<div class='spinner-container'>
<div class='spinner'>
<% 8.times do %>
<div>
<div></div>
</div>
<% end %>
</div>
</div>
@TeWu
TeWu / PID.rb
Last active July 17, 2018 10:39
PID Controller
class PID
attr_reader :kp, :ki, :kd, :output, :previous_error
attr_accessor :setpoint, :history_depth, :output_range, :invert_output
def initialize(setpoint, options = {})
@setpoint = setpoint
@kp = options[:kp] || 1
@ki = options[:ki] || 0
@kd = options[:kd] || 0
<?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" />