Skip to content

Instantly share code, notes, and snippets.

View zmajstor's full-sized avatar

Zoran Majstorovic zmajstor

View GitHub Profile
@zmajstor
zmajstor / pulsar.scss
Created June 8, 2015 08:43
AJAX loading ...
.change_pending {
box-shadow: 0 0 10px 2px #eee;
-webkit-animation: scaleout 1.0s infinite ease-in-out;
animation: scaleout 1.0s infinite ease-in-out;
}
@-webkit-keyframes scaleout {
0% { -webkit-transform: scale(0.0) }
100% { -webkit-transform: scale(1.0); opacity: 0; }
}
@zmajstor
zmajstor / README.md
Created February 17, 2015 22:54
AAI@EduH authentication for Ruby on Rails apps
@zmajstor
zmajstor / ca_chain.conf
Last active August 29, 2015 14:14
nginx for Rails development
# NGinx SSL certificate authentication signed by intermediate CA (chain)
# http://stackoverflow.com/questions/8431528/nginx-ssl-certificate-authentication-signed-by-intermediate-ca-chain?rq=1
server {
listen 443 ssl;
ssl_certificate ...
ssl_certificate_key ...
ssl_client_certificate /path/to/ca.crt;
@zmajstor
zmajstor / .bash_profile
Created November 28, 2014 12:23
dot files
xport PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
export EDITOR='mate -w'
# export LANG=hr_HR.UTF-8
@zmajstor
zmajstor / rails_encryptor.rb
Created September 14, 2014 14:47
ActiveSupport MessageVerifier and MessageEncryptor samples
require 'active_support'
require 'active_support/key_generator'
# KeyGenerator is part of Rails since v4.0.0
# https://github.com/rails/docrails/blob/master/activesupport/lib/active_support/key_generator.rb
salt = SecureRandom.random_bytes(64)
key = ActiveSupport::KeyGenerator.new('password1234').generate_key(salt)
encryptor = ActiveSupport::MessageEncryptor.new(key)
message = "Secret message in plain text"
@zmajstor
zmajstor / devices_controller.rb
Last active August 29, 2015 14:06
Simple API sample (responds with json or xml)
class API::V1::DevicesController < ApplicationController
before_filter :authenticate!
before_filter :find_device, only: [:update, :destroy, :capability, :push_mdm_commands]
skip_before_filter :verify_authenticity_token
respond_to :json, :xml
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found_error
# curl -v -k -X GET -H "Content-Type: application/json" -H "Accept: application/json" -H 'Authorization: Token token=justesting' https://localhost:8443/api/v1/devices
# default response format is json, append .xml for XML output: https://localhost:8443/api/v1/devices.xml
@zmajstor
zmajstor / smart_card_adapter.rb
Created August 23, 2014 12:21
SmartCard adapter using smartcard gem with demo
# http://www.rdoc.info/github/costan/smartcard/master/Smartcard
require 'smartcard'
class SmartCardAdapter
# scope of the smart-card connection; valid values are :system, :user, and :terminal
# (see the SCARD_SCOPE_ constants in the PC/SC API)
def connect(scope = :system)
@context = Smartcard::PCSC::Context.new(scope)
end
require 'openssl' unless defined? OpenSSL
# improved extraction and validation of the subjectAltName X509 extension for
# Universal Principal Name (UPN)
# Widely deployed Microsoft OtherName name form (OID 1.3.6.1.4.1.311.20.2.3)
# Format: user@domain
# Encoding: UTF-8
# Matching: case ignore
# e.g.
# otherName=1.3.6.1.4.1.311.20.2.3;UTF8:bobOtherAltName@example.com
require 'OpenSSL'
class KeyPair
attr_reader :key, :cert
def initialize serial, issuer=nil
@key = OpenSSL::PKey::RSA.new(1024)
@cert = OpenSSL::X509::Certificate.new
@cert.version = 2 # RFC 5280 - v3
@cert.serial = serial
@zmajstor
zmajstor / bootstrap_helper.rb
Created August 18, 2014 09:24
Bootstrap 3 rails helper for flash messages
module BootstrapHelper
# Bootstrap 3 helpers for Rails 4 Flash messages
# in Gemfile add line: gem 'bootstrap-sass', '~> 3.2.0'
# and <%= flash_messages %> in views/layouts/application.html.erb
# use in controllers: flash[:error] = 'Invalid email/password combination'
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
end