Skip to content

Instantly share code, notes, and snippets.

@txus
txus / emotiv-dump
Created November 26, 2013 20:40
Dump your recorded emokit-java sessions (from Postgresql) to a CSV file for easier analysis.
#!/usr/bin/env ruby
require 'pg'
require 'csv'
FIELDS = %w(af3 af3_quality af4 af4_quality f3 f3_quality f4 f4_quality f7 f7_quality f8 f8_quality fc5 fc5_quality fc6 fc6_quality o1 o1_quality o2 o2_quality p7 p7_quality p8 p8_quality t7 t7_quality t8 t8_quality timestamp)
def banner
abort "Usage: #{$PROGRAM_NAME} session_name output_file.csv"
end
@txus
txus / RATIONALE.md
Last active December 29, 2015 02:29
New API proposal for (block/closure) compilers in Rubinius

For language developers on the Rubinius platform, the APIs to the Rubinius generator and other compiler parts are generally very smooth and easy to use. An exception to this is when trying to generate a function/closure. Messing with the low-level APIs turns out to be unwieldy, as they tend to expose quite a lot of detail about Ruby-specific semantics.

The goal of this proposal is to provide a higher-level API optimized for a more general use case.

The file ast.rb contains the user code, and the file new_api.rb contains the support code to make it work (what would end up being implemented in some rubinius gem).

class Dog
def initialize(logger)
@logger = logger
end
def bark
puts "Bark!"
logger.log("Barked")
end
@txus
txus / gist:7231173
Last active December 26, 2015 23:29
Creating and cultivating intrinsic motivation
Autonomy, confidence and role models are essential to intrinsic motivation to
perform any activity X, where X could be for example "writing".
* Autonomy on how and when to perform the task is crucial -- for example, if
you are assigned a writing task and you have very specific guidelines, the
stricter those are, the worse the effect on intrinsic motivation.
* Confidence: you need to be certain that you actually can perform the task
with little or no supervision, and that you can either figure out things when
you're stuck or ask for a second opinion as a last resort. You need to be
dogs, cats = params[:questions]
.select { |k,v| v == true}
.map { |k,v| Question.find(k).category }
.partition { |e| e == "dog" }
if dogs.count > cats.count
"dog lover!!"
elsif dogs.count == cats.count
"plant lover"
else
@txus
txus / kwargs.rb
Created September 24, 2013 13:43
Enforcing arity with keyword arguments? well no because computer
def foo(a: 1,
b: raise(ArgumentError, "need b"),
c: 42)
# lol
end
@txus
txus / transients.rb
Created September 19, 2013 10:54
Transients in Ruby. Transients are a way to mutate an immutable object for a limited scope of changes and then make it immutable again.
class Object
def transient(&block)
dup.tap(&block).freeze
end
end
str = "hey".freeze
new_str = str.transient do |mutable_str|
mutable_str.upcase!
aejij
aeigj
@txus
txus / duplex.rb
Created August 29, 2013 16:37
Broadcast TCP traffic. Spike
require 'celluloid/io'
module Duplex
class Server
include Celluloid::IO
finalizer :finalize
def initialize(name, host, port)
@name = name
puts "[#{name}] *** Starting server on #{host}:#{port}"
@txus
txus / Rakefile
Created August 22, 2013 12:09
Example
namespace :fegonigans do
desc "It shenanifies fegonigans"
task :shenanify do
...
end
end