Skip to content

Instantly share code, notes, and snippets.

View am-kantox's full-sized avatar
🎩
constantly matching the patterns

Aleksei Matiushkin am-kantox

🎩
constantly matching the patterns
View GitHub Profile
@am-kantox
am-kantox / sensible-array.rb
Created April 9, 2015 12:46
Sensible Arrays
module Sensible
module Array
class ::Array
alias_method :select_std, :select
def select arg = nil, &cb
preselected = case arg
# no argument ⇒ standard processing
when NilClass then self
# strings are matched as is
when String then select_std do |e|
export TERM=xterm-256color
# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
@am-kantox
am-kantox / rapid-miner-server.sh
Last active September 12, 2016 11:50
init.d service to start/stop/restart RapidMiner Server
#!/bin/sh
RMS=`basename "$0"`
RMS_HOME=/home/ubuntu/Apps/rms
application_start() {
echo -n "Starting RapidMiner Server daemon... "
# to satisfy fcuking RMS, run as a user:
# sudo -u ubuntu $RMS_HOME/bin/standalone.sh 2>&1 > $RMS_HOME/log/$RMS-$(date +"%m-%d-%y").log &
$RMS_HOME/bin/standalone.sh 2>&1 >/var/log/$RMS.log &
@am-kantox
am-kantox / RMS_Installer.xml
Last active August 29, 2015 14:26
RMS_Installer.xml template for headless installation
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="db_url">localhost</entry>
<entry key="db_port">3306</entry>
<entry key="server_service_id_overwrite">null</entry>
<entry key="eula_accepted">true</entry>
<entry key="server_port">8080</entry>
<entry key="db_password">*******</entry>
<entry key="mail_password"/>
@am-kantox
am-kantox / progress_bar.rb
Last active November 24, 2016 09:45
ProgressBar in ruby (e. g. for console rakes.)
class ProgressBar
RUNNING = %W{👆 👇 👈 👉 👊}.freeze
attr_reader :count, :position
def initialize caption, count, running = RUNNING
@count = count
@caption = " #{caption} "
@running = running.cycle
@position = 0
# based on agnoster zsh prompt
# vim:ft=zsh ts=2 sw=2 sts=2
#
# mudasobwa's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
@am-kantox
am-kantox / .iex.exs
Created March 3, 2017 06:29
Fancy IEx config
# IEx.configure colors: [enabled: true]
# IEx.configure colors: [eval_result: [:cyan, :bright]]
{fortune, 0} = System.cmd "fortune", [] # displays the fortune prompt
IO.puts IO.ANSI.red_background() <> IO.ANSI.white() <> "▷ #{fortune}" <> IO.ANSI.reset
Application.put_env(:elixir, :ansi_enabled, true)
IEx.configure(
colors: [
eval_result: [:green, :bright] ,
eval_error: [[:red, :bright, "\n▶▶▶\n"]],
eval_info: [:yellow, :bright ],
@am-kantox
am-kantox / digest_benchmark.rb
Created March 29, 2017 14:28
Ruby :: benchmark of different digests
require 'benchmark/ips'
n = 500000
require 'digest/md5'
require 'digest/sha1'
require 'digest/sha2'
require 'digest/sha3' # https://github.com/phusion/digest-sha3-ruby
INPUT = [5, "Hello, world", nil]
@am-kantox
am-kantox / log.ex
Created April 24, 2017 15:55
Making a sibling for lazy Elixir `Logger`
defmodule Eventory.Helpers.Log do
@moduledoc false
Enum.each(~w|error info warn debug|a, fn level ->
Module.register_attribute(__MODULE__, :level, persist: false)
Module.put_attribute(__MODULE__, :level, level)
defmacro unquote(Module.get_attribute(__MODULE__, :level))(chardata_or_fun, metadata \\ []) do
{{:., [], [
{:__aliases__, [alias: false], [:Logger]},
unquote(Module.get_attribute(__MODULE__, :level))]},
@am-kantox
am-kantox / finally_ensuring.rb
Last active May 24, 2017 09:43
Don’t ask this on interviews!
def a1
:normal
ensure
:ensure
end
def a2
return :normal
ensure
return :ensure