Skip to content

Instantly share code, notes, and snippets.

View alekpopovic's full-sized avatar
🏠
Working from home

Aleksandar Popovic alekpopovic

🏠
Working from home
View GitHub Profile
@alekpopovic
alekpopovic / record_nock_to_json_file.js
Created November 2, 2020 22:13 — forked from pconerly/record_nock_to_json_file.js
Record nocks to a json file
var nock = require('nock');
var low = require('lowdb');
// lowdb is a great straight-to-json minidb.
var db = low('integration_test_nock_records.json');
writeToFileLog = function(object) {
console.log("writing nock to json....");
db('records').push(object);
}
@alekpopovic
alekpopovic / oauth.js
Created October 28, 2020 13:08 — forked from srph/oauth.js
axios: interceptor which includes your oauth token in every request as an Authorization header
import axios from 'axios';
// You can use any cookie library or whatever
// library to access your client storage.
import cookie from 'cookie-machine';
axios.interceptors.request.use(function(config) {
const token = cookie.get(__TOKEN_KEY__);
if ( token != null ) {
config.headers.Authorization = `Bearer ${token}`;
@alekpopovic
alekpopovic / axios-interceptors-refresh-token.js
Created October 26, 2020 10:40 — forked from mkjiau/axios-interceptors-refresh-token.js
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {
@alekpopovic
alekpopovic / puma.rb
Created October 9, 2020 17:47 — forked from danielalvarenga/puma.rb
Puma config for rails 5 api
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
# More: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#threads
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
@alekpopovic
alekpopovic / mysql.rake
Created October 1, 2020 11:39 — forked from dfl/mysql.rake
rails rake tasks for dumping and reloading mysql databases
# mysql db backup and restore for rails
# by David Lowenfels <[email protected]> 4/2011
require 'yaml'
namespace :db do
def backup_prep
@directory = File.join(RAILS_ROOT, 'db', 'backup')
@db = YAML::load( File.open( File.join(RAILS_ROOT, 'config', 'database.yml') ) )[ RAILS_ENV ]
@db_params = "-u #{@db['username']} #{@db['database']}"
@alekpopovic
alekpopovic / ruby-ftp-get-all-files.rb
Created August 28, 2020 18:12 — forked from beepony/ruby-ftp-get-all-files.rb
ruby ftp list all files
require 'net/ftp'
def scan(ftp, dir)
ftp.chdir(dir)
puts ftp.pwd + "/."
entries = ftp.list('*')
entries.each do |entry|
if entry.split(/\s+/)[0][0,1] == "d" then
scan(ftp, entry.split.last)
else
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Component.extend({
redirection: service(),
tagName: ''
});
@alekpopovic
alekpopovic / pg_pub_sub.rb
Created July 17, 2020 00:01 — forked from chsh/pg_pub_sub.rb
PostgreSQL LISTEN/NOTIFY example for ruby
#
# A:
# pubsub = PgPubSub.new('channelname')
# pubsub.subscribe do |data|
# puts "data: #{data} is coming!"
# end
#
# B:
# pubsub = PgPubSub.new('channelname')
# pubsub.publish("hello world")
@alekpopovic
alekpopovic / github_gpg_key.md
Created July 12, 2020 11:19 — forked from ankurk91/github_gpg_key.md
Github : Signing commits using GPG (Ubuntu/Mac)

Github : Signing commits using GPG (Ubuntu/Mac) 🔐

  • Do you have an Github account ? If not create one.
  • Install required tools
  • Latest Git Client
  • gpg tools
# Ubuntu
sudo apt-get install gpa seahorse
# MacOS with https://brew.sh/