Skip to content

Instantly share code, notes, and snippets.

View verticonaut's full-sized avatar

Martin Schweizer verticonaut

  • private
  • Stans, Switzerland
View GitHub Profile
@verticonaut
verticonaut / secure_compare.rb
Created January 18, 2023 10:29
secure string comparison in ruby
# plain ruby
def secure_compare(a, b)
return false if a.empty? || b.empty? || a.bytesize != b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
@verticonaut
verticonaut / global-object.js
Created January 7, 2021 09:15
Declare global object in JS
class Validator {}
var global = window || global;
global.Validator = Validator;
@verticonaut
verticonaut / .gitconfig
Last active March 26, 2020 12:04
Global gitconfig file
[user]
name = <yourname>
email = <youre email>
[alias]
co = checkout
unpushed = diff origin/master..HEAD --name-status
rpo = remote prune origin
notmerged = branch --no-merged
merged = branch --merged
[color]
@verticonaut
verticonaut / mv_many_files
Created August 6, 2019 09:08
copy many files
for f in huk/*.*; do mv "$f" ./; done
@verticonaut
verticonaut / pry-cheatsheet
Created December 12, 2018 08:24
pry-cheatsheet
Pry Cheat Sheet
Youtube Tutorial 2013
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
pry -r ./config/environment.rb - load your rails into a pry session
Debugger
help ls -- Display command options for pry command ls
ls <Object> -- Show all of the available methods that can be called by an object
@verticonaut
verticonaut / pry-cheatsheet
Created December 12, 2018 08:23
pry-cheatsheet
Pry Cheat Sheet
Youtube Tutorial 2013
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
pry -r ./config/environment.rb - load your rails into a pry session
Debugger
help ls -- Display command options for pry command ls
ls <Object> -- Show all of the available methods that can be called by an object
@verticonaut
verticonaut / port_processes.txt
Created July 23, 2018 09:23
find processes aon ports
lsof -nP -iTCP:3000 | grep LISTEN
@verticonaut
verticonaut / docker_commands.txt
Created January 17, 2018 12:57
Docker commands
docker ps
# running docker container
docker stop <contaienrId>
# stop the container
docker images
# list all installed images
# Start containers ==========================================
# REDIS
docker run -it --rm -p 6379:6379 -d --name redis redis:alpine
@verticonaut
verticonaut / docker_commands.txt
Created January 17, 2018 12:57
Docker commands
docker ps
# running docker container
docker stop <contaienrId>
# stop the container
docker images
# list all installed images
# Start containers ==========================================
# REDIS
docker run -it --rm -p 6379:6379 -d --name redis redis:alpine
@verticonaut
verticonaut / property_struct.rb
Last active December 19, 2015 02:28
Read and write in property style. Sample: ps = PropertyStruct.new; p['a1.a2.a3']=3 ps['a1'] = #<PropertyStruct:...> ps['a1.a2.a3'] = 3
class PropertyStruct
def initialize(nil_safe = true)
@nil_safe = !!nil_safe
@data = {}
end
def [](attribute)
result = @data