Skip to content

Instantly share code, notes, and snippets.

@ffloyd
ffloyd / matching.rb
Last active September 22, 2018 08:32
Elixir-like matching for ruby proposal
# example function
def f
[:ok, 'bla bla']
end
#
# elixir-like offensive matching (match or exception)
#
# success case
#####################################################################################
####### Benchmarking infrastructure (no significant busuness logic involved) #######
#####################################################################################
####### Naive PORO realization
Warming up --------------------------------------
NativeNaive [prepared]
@ffloyd
ffloyd / .spacemacs
Created January 29, 2017 17:36
spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@ffloyd
ffloyd / trailblazer.rb
Created September 28, 2016 09:59
heavy_control
HeavyControl.config do
ignore_subfolder 'operation'
ignore_subfolder 'operations'
# when you face error warning like 'warning: toplevel constant YourClass referenced by YourContext::YourClass'
# just add 'YourContext::YourClass' to always_load
always_load 'Organization::Admin', 'Organization::Cell',
'Course::Admin', 'Course::Cell'
end
func flattenSlice(input *[][]interface{}) *[]interface{} {
capSum := 0
for _, v := range *input {
capSum += cap(v)
}
result := make([]interface{}, 0, capSum)
for _, v := range *input {
result = append(result, v)
}
return &result
@ffloyd
ffloyd / workflow.rb
Created April 6, 2016 12:48
statesman
# use only for possible transitions check
class IndividualWebinar::Workflow
include Statesman::Machine
def initialize(webinar)
@webinar = webinar
end
state :planned
state :waiting_for_teacher
@ffloyd
ffloyd / trailblazer_loader.rb
Created April 6, 2016 11:35
example (draft) heavy_control config
HeavyControl.config do
root :concepts do # all stuff loaded in recursive lexicographical order, deep files last
common do
no_scope :operations # concepts/aaa/operations/bbb.rb will be pointed to Aaa::Bbb instead of Aaa::Operations::Bbb
# it's like we move all files out of operations folder
prioritize_file :policy # will load policy.rb before any other files and directories in folder
prioritize_folder :generators # will load generators folder before any other files and directories in folder, except :policy
end
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@ffloyd
ffloyd / double_method.rb
Last active August 29, 2015 14:06
double_method
require 'benchmark'
require 'active_support'
module Hello
extend ActiveSupport::Concern
BENCH_ITERS = 1_000_000
included do
double_method :hello_double, :hello
object Problem1001 {
def main(args: Array[String]) {
val numbersStrings = io.Source.stdin.getLines()
val squares = numbersStrings.flatMap {
_.split(" ").filterNot { _.isEmpty }.map { x => math.sqrt(x.toLong) }
}.toArray.reverse
println(squares.mkString("\n"))
}
}