Skip to content

Instantly share code, notes, and snippets.

View bosskovic's full-sized avatar

Marko Bošković bosskovic

  • Jomb AG
  • Novi Sad, Serbia
View GitHub Profile
@bosskovic
bosskovic / api_constraints.rb
Created August 19, 2014 18:56
Rails API versioning
# lib/api_constraints.rb
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
@domain = options[:domain]
end
def matches?(req)
@bosskovic
bosskovic / I18n_test.php
Last active March 14, 2023 02:13
Example of PHP file translated using gettext
<?php
session_start();
if (isset($_GET["locale"])) {
$locale = $_GET["locale"];
}
else if (isset($_SESSION["locale"])) {
$locale = $_SESSION["locale"];
}
else {
@bosskovic
bosskovic / Gemfile
Last active September 21, 2022 14:24
Devise as authentication solution for rails API
gem 'devise', '3.2.4'
gem 'simple_token_authentication', '1.5.0'
@bosskovic
bosskovic / example.po
Last active March 14, 2022 09:43
A simple example of a PO file
msgid ""
msgstr ""
"Project-Id-Version: Lingohub 1.0.1\n"
"Report-Msgid-Bugs-To: support@lingohub.com \n"
"Last-Translator: Marko Bošković <marko@lingohub.com>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
$(document).ready(function() {
var $container = $('#translators')
$($container).isotope({
itemSelector: '.item',
masonry: {
columnWidth: 280
}
})
@bosskovic
bosskovic / example.resx
Created April 9, 2013 09:18
example of RESX/RESW resource file
<?xml version="1.0" encoding="utf-8"?>
<root>
<data name="Common_AuthenicationFailed" xml:space="preserve">
<value>Authentifikation fehlgeschlagen</value>
</data>
<!-- single line comment -->
<data name="Common_Billable" xml:space="preserve">
<value>Verrechenbar</value>
</data>
<!-- multi
@bosskovic
bosskovic / Gemfile
Last active November 30, 2018 19:19
Developing rails REST API with Cucumber
. . .
group :test do
gem 'cucumber-rails', '1.4.1', :require => false
gem 'json_spec', '1.1.2'
. . .
@bosskovic
bosskovic / json_localization.php
Last active August 16, 2017 05:01
Example of localization using json
<?php
// the original of this code can be found on:
// http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/
function localize($phrase) {
/* Static keyword is used to ensure the file is loaded only once */
static $translations = NULL;
if (is_null($translations)) {
$lang_file = '/lang/' . $_SESSION["locale"] . '.txt';
/* If no instance of $translations has occured load the language file */
@bosskovic
bosskovic / aws_s3_reupload.rake
Last active December 28, 2015 10:19
An example of a rake task for re-uploading the aws files.
namespace :s3_files do
desc 'Reuploads the s3 files from the old locations'
task :reupload => :environment do
ok = 0
not_ok = 0
puts ' ', '-----', 'Re-uploading User avatars'
User.where('avatar IS NOT NULL').each do |user|
new_path = "uploads/user/#{user.uuid.to_s}/avatar"
@bosskovic
bosskovic / avatar_uploader.rb
Last active December 28, 2015 10:18
Example of using carrierwave to manage file uploads
require 'carrierwave/processing/mime_types'
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::Processing::MiniMagick
include CarrierWave::MimeTypes
# Changes the file content_type using the mime-types gem
process :set_content_type