Skip to content

Instantly share code, notes, and snippets.

View katafrakt's full-sized avatar
🐟

Paweł Świątkowski katafrakt

🐟
View GitHub Profile
@katafrakt
katafrakt / puma_rc.d.sh
Created October 11, 2012 18:59
simple and stupid Arch Linux rc.d script for starting and stopping puma (http://puma.io) with certain rails app
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/profile
DAEMON=prozatorium
PIDFILE=/path/to/pidfile
app_path=/path/to/rails_app
config=config/puma.rb
/**
* jQuery background position plugin
* adapted to width recalculation
* original by Alexander Farkas
*/
(function($) {
Tween = jQuery.Tween;
jQuery.Tween.prototype.run = function( percent ) {
var eased,
# From: http://nerdblog.pl/post/120106238519/node-on-execjs-is-sloooooow
# with bmbm
# 2 + 2
Rehearsal ------------------------------------------------
node.js 0.080000 0.010000 0.090000 ( 0.080896)
therubyracer 0.060000 0.010000 0.070000 ( 0.065395)
--------------------------------------- total: 0.160000sec
@katafrakt
katafrakt / connect_to_rethinkdb.d
Last active September 9, 2015 09:09
Connect to RethinkDB from D
import std.stdio, std.socket, std.socketstream, std.stream, std.string, std.conv;
import dproto.dproto;
const proto_def = import("ql2.proto");
mixin ProtocolBufferFromString!proto_def;
void main()
{
auto socket = new TcpSocket(AddressFamily.INET);
socket.connect(new InternetAddress("localhost", 28015));
@katafrakt
katafrakt / output
Created January 19, 2016 11:09
RethinkDB compilation errors
[44/396] CC build/release/obj/clustering/table_manager/multi_table_manager.o
In file included from ./src/clustering/administration/servers/server_metadata.hpp:10:0,
from ./src/clustering/administration/tables/table_metadata.hpp:12,
from ./src/clustering/table_contract/contract_metadata.hpp:12,
from ./src/clustering/table_contract/coordinator/coordinator.hpp:6,
from ./src/clustering/table_manager/table_manager.hpp:5,
from ./src/clustering/table_manager/multi_table_manager.hpp:8,
from src/clustering/table_manager/multi_table_manager.cc:2:
./src/rpc/mailbox/typed.hpp: In member function ‘void mailbox_t<void(a0_t, a1_t, a2_t, a3_t, a4_t, a5_t, a6_t, a7_t)>::read_impl_t::read(read_stream_t*, signal_t*) [with arg0_t = uuid_u; arg1_t = multi_table_manager_timestamp_t; arg2_t = multi_table_manager_bcard_t::status_t; arg3_t = boost::optional<table_basic_config_t>; arg4_t = boost::optional<raft_member_id_t>; arg5_t
@katafrakt
katafrakt / horror.rb
Created March 12, 2016 15:30
A quality ruby code
@image_type = params[:image][:type] ? params[:image][:type] : nil
@show_uploader = params[:uploader] == 'false' ? false : true
@katafrakt
katafrakt / question.rb
Last active June 1, 2016 10:52
Which pattern-matching syntax is better?
# Which pattern-matching syntax you think is better in Ruby?
#
# Some background:
# - https://github.com/katafrakt/noaidi
# - http://katafrakt.me/2016/02/13/quest-for-pattern-matching-in-ruby/
# - http://katafrakt.me/2016/05/24/refactoring-rails-with-noaidi/
# Syntax 1:
require 'rom'
require 'rom/sql'
require 'pg'
# Assuming a database with tables 'users' and 'projects'
rom = ROM.container(:sql, 'postgres://localhost/test')
#
# # Perhaps one Repo to handle users
class UserRepo < ROM::Repository[:users]
end
@katafrakt
katafrakt / printer.rb
Last active December 13, 2017 09:53
This is probably my first real Ruby code ever - it prints specified number of busines cards on a page, using PostScript, RTF or TeX and was an assignment for my university classes. Date on forgotten Dropbox account is March 2009, but I'm pretty sure it's from autumn 2007.
class Vcard
attr_reader :imie, :nazwisko, :firma, :telefon
def show
if not @imie
puts "Dane niezaładowane"
else
puts @imie + " " + @nazwisko
puts @firma
puts @telefon
end
@katafrakt
katafrakt / day_18.rb
Created December 18, 2017 21:12
Advent of Code 2017, day 18, referential Ruby implementation
class Program < Hash
Recv = Class.new(StandardError)
attr_reader :last_sound
def set(reg, val)
self[reg] = value(val)
end
def add(reg, val)
self[reg] += value(val)