Skip to content

Instantly share code, notes, and snippets.

@AMekss
AMekss / meta.yml
Created July 20, 2016 12:38
Generic meta for prmd
"$schema": "http://json-schema.org/draft-04/hyper-schema"
title: <Some title>
description: <Some descriotion>
id: <some_id>
links:
-
href: "<base_url>"
rel: self
@AMekss
AMekss / perfomance.rake
Created October 6, 2014 16:01
Capistrano 3 task performance reporter
require 'logger'
require 'colored'
class Capistrano::BM
attr_writer :logger
def initialize
@logger = Logger.new(STDOUT)
@start_times = {}
@end_times = {}
### Keybase proof
I hereby claim:
* I am amekss on github.
* I am amekss (https://keybase.io/amekss) on keybase.
* I have a public key whose fingerprint is C6D4 9BE7 7E7A ED2E 94D9 E9C7 5088 C3B2 22A6 CEF4
To claim this, I am signing this object:
@AMekss
AMekss / devise.lv.yml
Last active January 2, 2016 00:19
Compatible with Devise 3.2.2
# https://gist.github.com/AMekss/8222620
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n
lv:
devise:
confirmations:
confirmed: 'Jūsu lietotājs ir veiksmīgi apstiprināts. Jūs esat pieslēdzies.'
send_instructions: 'Pāris minūšu laikā uz Jūsu epastu tiks nosūtīts apraksts, kā apstiprināt Jūsu lietotāju.'
send_paranoid_instructions: 'Ja Jūsu parole eksistē mūsu datubāzē, tad pāris minūšu laikā uz Jūsu epastu tiks nosūtīts apraksts, kā apstiprināt Jūsu lietotāju.'
failure:
@AMekss
AMekss / ranged_hash.rb
Created October 19, 2012 08:22
RangedHash implementation in Ruby
class RangedHash
def initialize(hash={})
@ranged_hash = hash
end
def [](key)
(@ranged_hash.detect{|range, value| range.cover?(key) } || []).last
end
def []=(key, value)
@AMekss
AMekss / string.rb
Created October 9, 2012 10:56
String#normalize_encoding! for working with differently encoded strings in Ruby 1.9.3
# -*- encoding : utf-8 -*-
class String
# method always returns string with valid encoding which is equal to Encoding#default_internal
# handy for working with strings which encoding may differ (all kinds of imports and free text inputs)
def normalize_encoding!
return self unless !!defined?(Encoding) # apply for Ruby 1.9.3 only
encoding_equal_to_default_internal = (self.encoding == Encoding.default_internal)
# return unchanged if encoding is valid and equal to default_internal
@AMekss
AMekss / application_helper.rb
Created July 10, 2012 05:55
Rails view helper for extracting value by path string
# -*- encoding : utf-8 -*-
module ApplicationHelper
def read_value_from(object, path_string, alt_value=nil)
return alt_value unless object && path_string
value = object
path_string.split(".").each do |path_component|
return alt_value unless value.respond_to?(path_component.to_sym)
value = value.send(path_component.to_sym)
end
value
@AMekss
AMekss / instance_caching.rb
Last active September 23, 2023 07:25
Convinient and simple way how to do instance level caching.
# Source: https://gist.github.com/ceb528f97638c45ad6c7
# Replacement for direct @var ||= solution but this one correctly memoize non-true values (nil, false, etc) and is simple..
# Much simpler than ActiveSupport::Memoize which is deprecated (in Rails 3.2) by the way
module InstanceCaching
def remember(*args)
caller_name = caller(1..1).first[/`(.*)'/, 1]
caller_args_digest = Digest::MD5.hexdigest(args.to_s)
cache = @instance_caching_memoizations_aw5zdgf ||= {}
cache_key = "#{caller_name}_#{caller_args_digest}"
@AMekss
AMekss / namespace.js
Created June 26, 2012 08:47
Helper for global javascript namespace definition
// The MIT License (MIT) => http://www.opensource.org/licenses/mit-license
// Copyright (c) 2012 Artūrs Mekšs
//
// Runtime depndency jQuery 1.4 or above
(function($, rootspace){
window[rootspace] = function(namespace, object){
var setNamespace = function(namespace){
var root = window[rootspace];
$(namespace.split(".")).each(function(idx, name){
root = root[name] = root[name] || {};
@AMekss
AMekss / ClassXMLProcessor.ls
Created October 26, 2011 17:03
This class provides methods for XML structured data processing in Lotus Script.
%REM
Copyright 2009 TietoEnator Alise (developed by Arturs Mekss)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software