Skip to content

Instantly share code, notes, and snippets.

View zmajstor's full-sized avatar

Zoran Majstorovic zmajstor

View GitHub Profile
@deargle
deargle / client.conf
Last active February 16, 2024 20:14
OpenVPN server.conf and client.conf
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 3, 2024 20:10
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@chinchang
chinchang / xmlToJson.js
Last active September 7, 2023 02:39
Function to convert XML to JSON
/**
* Changes XML to JSON
* Modified version from here: http://davidwalsh.name/convert-xml-json
* @param {string} xml XML DOM tree
*/
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) {
@janko
janko / keyword_arguments.rb
Last active July 24, 2018 08:34
Ruby keyword arguments advantages and use cases
####
# 1. Simple assertion of required arguments
####
# - You can forget #fetch
# - You get a better error, and always on the line where method is defined
def search(options = {})
query = options.fetch(:query)
end
search() # => KeyError: key not found :query
@bobbygrace
bobbygrace / trello-css-guide.md
Last active April 2, 2024 20:18
Trello CSS Guide

Hello, visitors! If you want an updated version of this styleguide in repo form with tons of real-life examples… check out Trellisheets! https://github.com/trello/trellisheets


Trello CSS Guide

“I perfectly understand our CSS. I never have any issues with cascading rules. I never have to use !important or inline styles. Even though somebody else wrote this bit of CSS, I know exactly how it works and how to extend it. Fixes are easy! I have a hard time breaking our CSS. I know exactly where to put new CSS. We use all of our CSS and it’s pretty small overall. When I delete a template, I know the exact corresponding CSS file and I can delete it all at once. Nothing gets left behind.”

You often hear updog saying stuff like this. Who’s updog? Not much, who is up with you?

@bruno-
bruno- / gist:eddd6298deaa4940c52c
Created August 13, 2014 19:05
signing git commits - cheat sheet

Article: http://mikegerwitz.com/papers/git-horror-story

Theory

  • faking other user's commits is easy with --author flag $ git commit --author='Foo Bar <foo@bar.com>' -m 'some commit'

  • signing commits ensures:

    • someone else can't commit as myself
  • I really commited all the commits I sign

@janko
janko / application.rb
Created June 7, 2014 16:57
Custom error pages in Rails
module MyApp
class Application < Rails::Application
# ...
config.exceptions_app = self.routes
config.action_dispatch.rescue_responses.merge!(
"RDS::ResourceNotFound" => :not_found,
)
# ...
end
@janko
janko / ldap.rb
Last active August 29, 2015 14:02
Example Faraday integration with the LDAP protocol, with caching to the database.
require "faraday"
module Faraday
class Adapter
class NetLdap < Faraday::Adapter
def call(env)
# LDAP request, and call `save_response(env, status, body, headers)`
@app.call(env)
end
end
@javan
javan / application_controller.rb
Created November 30, 2013 22:06
Prevent cross-origin js requests
class ApplicationController < ActionController::Base
before_filter :ensure_xhr
private
def ensure_xhr
if request.get? && request.format && (request.format.js? || request.format.json?)
head :forbidden unless request.xhr?
end
end
end
@mitfik
mitfik / ruby_csr_example.rb
Created February 27, 2012 10:13
Ruby example of CSR with openssl
require 'openssl'
def gen_key(name)
key = OpenSSL::PKey::RSA.new 1048
file = File.new(name, "w")
file.write(key)
file.close
end
def get_key(name)