Skip to content

Instantly share code, notes, and snippets.

Vlado Cingel vlado

Block or report user

Report or block vlado

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vlado
vlado / encrypt_decrypt.sh
Created Jan 28, 2019
Encrypt/Decrypt file on macOs
View encrypt_decrypt.sh
# Encrypt
openssl aes-256-cbc -salt -in filename.ext -out filename.enc
# Decrypt
openssl aes-256-cbc -d -salt -in filename.enc -out filename.ext
@vlado
vlado / appointment.rb
Last active Oct 8, 2017
Rails bug when creating using association and scopes?
View appointment.rb
class Appointment < ApplicationRecord
belongs_to :inquiry
enum appointment_type: { default: 0, q1: 1, q2: 2 }
scope :q1, -> { where(appointment_type: q1) }
scope :on_date, -> (date) { where(scheduled_date: date) }
before_validation :set_start_and_end_time
def duration
[15, 30, 45].sample
@vlado
vlado / install_neo4j_on_semaphore_ci.sh
Last active Aug 5, 2016
Install Neo4j on Semaphore CI
View install_neo4j_on_semaphore_ci.sh
#! /usr/bin/env bash
set -e
source /opt/change-java-version.sh
change-java-version 8
wget -O - https://debian.neo4j.org/neotechnology.gpg.key | sudo apt-key add -
echo 'deb http://debian.neo4j.org/repo stable/' >/tmp/neo4j.list
sudo mv /tmp/neo4j.list /etc/apt/sources.list.d
sudo apt-get update
View example.rb
# https://minhajuddin.com/2016/03/03/put-this-in-your-code-to-debug-anything
require 'rouge'
require 'method_source'
require 'pp'
class Dbg
def initialize(object, to:)
@object, @stream = object, to
end
@vlado
vlado / add_empty_check_for_name_and_ams_key_to_carriers.rb
Last active Feb 18, 2016
Postgres constraints and triggers migration examples
View add_empty_check_for_name_and_ams_key_to_carriers.rb
class AddEmptyCheckForNameAndAmsKeyToCarriers < ActiveRecord::Migration
def up
execute %{
ALTER TABLE carriers
ADD CONSTRAINT check_carriers_name_is_not_empty
CHECK (name <> '');
}
execute %{
ALTER TABLE carriers
ADD CONSTRAINT check_carriers_ams_key_is_not_empty
View reindex_updater_store.rb
module ElasticsearchSupport
class ReindexUpdaterStore
class << self
def redis
$redis
end
def start(klass)
@vlado
vlado / bd_upgrade_es_on_semaphoreci.sh
Last active Mar 25, 2016
[BD] Upgrade Elasticsearch on SemaphoreCI
View bd_upgrade_es_on_semaphoreci.sh
rbenv global 2.2.2
sudo service elasticsearch stop
if ! [ -e .semaphore-cache/elasticsearch-1.5.1.deb ]; then (cd .semaphore-cache; curl -OL https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.5.1.deb); fi
echo Y | sudo dpkg -i .semaphore-cache/elasticsearch-1.5.1.deb
sudo sh -c "echo 'script.disable_dynamic: false' >> /etc/elasticsearch/elasticsearch.yml"
sudo service elasticsearch start
sleep 5 && curl -XGET 'localhost:9200'
@vlado
vlado / search_to_recommend.groovy
Created Apr 22, 2015
[BD] Groovy script to calculate custom scoring when recommending physician
View search_to_recommend.groovy
if (doc['primary_specialization_name'].value == specialization_name) {
_score + 1000
} else {
_score
}
View role_example.yml
permissions:
some_role:
- physicians # Can access all actions in physicians controller
- admin/inquiries#index # Can access index action in inquiries controller
some_other_role:
- physicians#show
- admin/inquiries
- admin/users
@vlado
vlado / controller_helpers.rb
Last active Feb 16, 2019
Stub devise authentication in controller specs with multiple scopes
View controller_helpers.rb
# Usage:
# fake_sign_in
# fake_sign_in(@user)
# fake_sign_in(@admin)
# fake_sign_in(:admin)
# fake_sign_in(@some_object, :scope => :user)
# fake_sign_out
# fake_sign_out :admin
module ControllerHelpers
You can’t perform that action at this time.