Skip to content

Instantly share code, notes, and snippets.

View dux's full-sized avatar

Dino Reić dux

  • Trifolium
  • London, Zagreb, Berlin
View GitHub Profile
@dux
dux / backup_database.rb
Created April 24, 2017 09:39
Postgre backup script, trigger from another server
#!/usr/bin/env ruby
require 'dotenv'
Dir.chdir '/home/deployer/apps/APP'
Dotenv.load
DB_HOST = 'user@host'
DB_NAME = ENV['DB_NAME']
@dux
dux / pull-request-prepare.rb
Last active March 2, 2022 19:06
prepares github pull request with full clean view of the selected files
#!/usr/bin/env ruby
# prepares github pull request with full clean view of the selected files
# to run it
# * delete some files after commit that is pushed, and leave them unstaged
# * pull-request-prepare.rb will
# * create branch-review-start with all marked files deleted
# * create branch-review-end with all marked files re-added
# * leave starting branch untouched
# * open github url for pull request
@dux
dux / _simple_mock.rb
Last active August 12, 2017 15:32
Simple mock - lightweight mocking, supports method mocks, sequences, traits
class SimpleMock
attr_reader :object
@@mock_data = {}
@@sequence ||= {}
class << self
def define name, &block
@@mock_data[name] = block
end
@dux
dux / g.rb
Created January 8, 2017 17:06
git helper, pull before push, nice logs, easy commits
#!/usr/bin/env ruby
require 'colorize'
@actions = {}
@branch = `git rev-parse --abbrev-ref HEAD`.to_s.chomp.sub(/\*\s/,'')
def cputs(data)
puts data.split("\n").map{ |el| " #{el}" }.join("\n")
end
@dux
dux / decorator_clone.rb
Last active October 20, 2023 13:51
Simple ruby decorators with example
class DecoratorClone
def initialize(model)
@model = model
end
def method_missing(m, *args)
raise NameError, "Decorator method '#{m}' not found" unless @model.respond_to?(m)
@model.send(m, *args)
end
end
@dux
dux / serialize-compact.js
Last active January 10, 2017 18:10
JavaScript Zepto or jQuery plugin to serialize form data to hash
// using built in jQuery and Zepto serializeArray()
/***
$('#form').serializeHash()
should return :
{
'user[name]': 'Dux'
}
***/
ok article https://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
but shorter and more accurate
1. in server manager as linode assign private IP address
2. ps aux | grep postgres
/usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
3. open postgresql.conf and set
@dux
dux / default_policy.rb
Created October 27, 2016 10:49
few simple policy objects
class DefaultPolicy < Policy
def before(action)
# return true for admins
admin?
end
def admin?
@user.try(:is_admin?) || false
end
# 1. fill markers/locations array
# 2. pass objects and draw them
# @markers = Model.all.inject([]) { |list, el| list.push({ id:el.id, lat:el.latitude, lng:el.longitude, name:el.name, city:el.city, path:el.admin_path }); list }
# ---
# var markers = #{@markers.to_json};
# GoogleMap.init('map2', { lat: 50.9188435, lng: 9.3206294, zoom: 6 });
# GoogleMap.add_markers(markers, function(o) {
# return '<div><b><a href="'+o.path+'">'+o.name+'</a></b><br /><br />'+o.city+'</div>'
# });
@dux
dux / pjax.coffee
Last active September 19, 2016 09:07
Vanilla JS PJAX module - turbolinks replacement
# Page.init '#full_page'
# Page.skip (el) -> ! /\/admin\//.test(el)
# Page.after_load ->
# window.initMap()
# $('.focus').first().focus();
# clearInterval(window.total_time_interval);
# alert 'loaded'
#
# Page.after_load()