Skip to content

Instantly share code, notes, and snippets.

View zmajstor's full-sized avatar

Zoran Majstorovic zmajstor

View GitHub Profile
@zmajstor
zmajstor / simpleApiPost.js
Created February 13, 2023 16:38
Simple HTTPS Post using node:https
const NODE_HTTPS = require('node:https')
const NODE_URL = require('node:url')
// resolves to response status code is success
const simpleApiPost = ({ endpointURL, body, bearerToken }) => new Promise((resolve, reject) => {
try {
const options = {
...NODE_URL.parse(endpointURL),
port: 443,
method: 'POST',
@zmajstor
zmajstor / usdTecajNaDan.gs
Last active February 12, 2023 10:07
USD srednji_tecaj in Google Sheets via HNB API V3
// Custom Functions in Google Sheets:
// https://developers.google.com/apps-script/guides/sheets/functions
//
function usdTecajNaDan(value) {
function formatDatum(value) {
switch (typeof value) {
case "string":
return value;
case "object":
// assuming it's a date object
# 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 December 12, 2023 11:39
Docker on CentOS Linux

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 December 15, 2018 14:08
MySQL DB Migration from localhost to AWS RDS
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 February 14, 2017 17:20
Herokuised Capistrano Tasks
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 December 15, 2016 10:39
current_user helpers without Devise
class ApplicationController < ActionController::Base
include SessionsHelper
Unauthorized = Class.new(StandardError)
def authorize_user!
raise Unauthorized unless current_user
end
end
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 = [
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 October 9, 2015 21:42
call ajax on SELECT change (in rails view)
<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() {