Skip to content

Instantly share code, notes, and snippets.

Avatar

Zoran Majstorovic zmajstor

  • Zagreb, Croatia
View GitHub Profile
View watch.ps1
# https://4sysops.com/archives/monitor-file-changes-in-windows-with-powershell-and-pswatch
# install with:
# iex ((new-object net.webclient).DownloadString("http://bit.ly/Install-PsWatch"))
Import-Module pswatch
watch ".\scss" | ForEach-Object {
write-host "Change made on $($_.Path)"
$sassc = 'C:\sassctest\proba-npm\proba-npm\sassc.exe'
$params = 'scss/style.scss css/style.css'.split(" ")
@zmajstor
zmajstor / 0-README.md
Last active Mar 8, 2020
Docker on CentOS Linux
View 0-README.md

NGINX reverse-proxy with Let's Encrypt Certs with Docker Compose

Acts as a single reverse proxy with SSL offloading for any number of dockerized web projects on a single server, using 2 awesome projects:

jwilder/nginx-proxy

  • the reverse proxy is be the only container that actually needs to expose any ports to the world.
  • base image is just a regular nginx
  • the only container that actually exposes anything to the outside world, both port 80 and 443
@zmajstor
zmajstor / migrating_mysql_to_rds.txt
Last active Dec 15, 2018
MySQL DB Migration from localhost to AWS RDS
View migrating_mysql_to_rds.txt
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Importing.External.Repl.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql_rds_stop_replication.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql_rds_reset_external_master.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_BestPractices.html
https://www.elitmus.com/blog/technology/setting-up-amazon-rds-as-a-slave-to-a-self-managed-mysql-server/
https://plusbryan.com/mysql-replication-without-downtime
https://www.borfast.com/blog/2014/02/15/how-to-add-a-slave-to-a-mysql-replication-setup-with-no-downtime/
http://stackoverflow.com/a/32716003
https://www.bonusbits.com/wiki/HowTo:Configure_iptables_to_Allow_Access_to_Common_Services_on_Linux
@zmajstor
zmajstor / info.rake
Created Feb 14, 2017
Herokuised Capistrano Tasks
View info.rake
namespace :info do
desc 'Show deployed revisions (releases)'
task :releases do
on roles(:app) do
within deploy_path do
with rails_env: "#{fetch(:stage)}" do
deployed_releases = capture(:tac, revision_log)
puts "=== #{fetch(:application)} releases:"
puts deployed_releases
@zmajstor
zmajstor / application_controller.rb
Last active Dec 15, 2016
current_user helpers without Devise
View application_controller.rb
class ApplicationController < ActionController::Base
include SessionsHelper
Unauthorized = Class.new(StandardError)
def authorize_user!
raise Unauthorized unless current_user
end
end
View openssl_asn1_decode_test.rb
require 'openssl'
require "minitest/autorun"
class OpenSSL::TestASN1 < Minitest::Test
def test_decode
subj = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=TestCA")
key = OpenSSL::TestUtils::TEST_KEY_RSA1024
now = Time.at(Time.now.to_i) # suppress usec
serial = 0xdeadbeafdeadbeafdeadbeafdeadbeaf
exts = [
View login_test.rb
require "minitest/mock"
require "test_helper"
class LoginTest < ActionDispatch::IntegrationTest
fixtures :pkis, :organizations, :users
def setup
@ldap_mock = Minitest::Mock.new
@ldap_mock.expect :tap, LdapStub.new
end
@zmajstor
zmajstor / my_view.html.erb
Created Oct 9, 2015
call ajax on SELECT change (in rails view)
View my_view.html.erb
<script type="text/javascript">
$(document).on("change", "#my_select", callAjax);
$.ajaxSetup({
headers: { 'X-CSRF-Token': '<%= form_authenticity_token.to_s %>' },
timeout: 30000, // timeout after 30 seconds
async: true,
});
function callAjax() {
@zmajstor
zmajstor / a_simple_role_based_authorization.md
Last active Aug 29, 2015
simple role-based authorization by current controller#action
View a_simple_role_based_authorization.md
@zmajstor
zmajstor / foo.html.erb
Created Jul 2, 2015
Ajax in Rails View with X-CSRF-Token
View foo.html.erb
<%= check_box_tag "foo[delivered]", nil, foo.delivered, data: { id: foo.id }, class: "delivered" %>
<script type="text/javascript">
$.ajaxSetup({
headers: { 'X-CSRF-Token': '<%= form_authenticity_token.to_s %>' },
timeout: 30000, // timeout after 30 seconds
async: true,
cache: false,
// dataType: "json", // The type of data that you're expecting back from the server