Skip to content

Instantly share code, notes, and snippets.

-module(expr).
-export([
parse/1,
test/0
]).
% ------------------------------------------------------
%
% Simple math-expressions parser
#Enable repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false
#Use current directory as default search scope in Finder
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
#Show Path bar in Finder
defaults write com.apple.finder ShowPathbar -bool true
#Show Status bar in Finder
#!/usr/bin/env escript
main([BeamFile]) ->
{ok, {_, [{abstract_code, {_, AC}}]}} = beam_lib:chunks(BeamFile, [abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
@artemeff
artemeff / mkcd.fish
Created April 30, 2015 22:45
Holy timesaver
function mkcd
mkdir $argv; and cd $argv
end
class Diff
def initialize(a, b)
@a, @b = a, b
end
def left
diff(@a, @b)
end
def right
module IdentifiedCollection
module ClassMethods
attr_reader :objects
def identify_by(identity)
@objects = Hash.new
@identity = identity
end
def identity
function ram
set -l sum 0
set -l app $argv[1]
if [ -z $app ]
echo "First argument - pattern to grep from processes"
else
for i in (ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}')
set sum (math $sum + $i)
end
@artemeff
artemeff / run
Created August 9, 2015 19:49
runit with erlang and relx
#!/bin/sh
APP=<application_name>
USER=user
ROOT=/home/$USER/apps/$APP/_rel/$APP
export HOME=/home/$USER
exec 2>&1
exec chpst -u $USER $ROOT/bin/$APP foreground
lager:debug("throughput ~p num/s", [length(State)]).
% transforms to
case {whereis(lager_event), whereis(lager_event), lager_config:get({lager_event, loglevel}, {0, []})} of
{undefined, undefined, _} ->
fun () -> {error, lager_not_running} end();
{undefined, _, _} ->
fun () -> {error, {sink_not_configured, lager_event}} end();
{__Pidfb_throughput43, _, {__Levelfb_throughput43, __Tracesfb_throughput43}} when __Levelfb_throughput43 band 128 /= 0 orelse __Tracesfb_throughput43 /= [] ->
lager:do_log(debug, [{application, fb}, {module, fb_throughput}, {function, handle_info}, {line, 43}, {pid, pid_to_list(self())}, {node, node()} | lager:md()], "throughput ~p num/s", [length(State)], 4096, 128, __Levelfb_throughput43, __Tracesfb_throughput43, lager_event, __Pidfb_throughput43);
@artemeff
artemeff / tip.rb
Last active December 19, 2015 11:29
Ruby tips
# string merging
"asd" "qwe" "zxc"
# => "asdqwezxc"
# separators may be a space
% sometext .size
# => 8