Skip to content

Instantly share code, notes, and snippets.

View hkraji's full-sized avatar

Haris Krajina hkraji

  • Cron
  • Sarajevo, Bosnia and Herzegovina
View GitHub Profile
@hkraji
hkraji / rdebugrc
Last active December 24, 2015 07:18
Rdebugrc, ruby debug
### Ruby
## Breakpoint
# DEBUG SNIPPET >>> REMOVE <<<
require (RUBY_VERSION.match(/1\.8\..*/) ? 'ruby-debug' : 'debugger');Debugger.start; debugger
### System
@hkraji
hkraji / gist:7526519
Last active December 28, 2015 16:09
Hash to OpenStruct nested convert
require 'ostruct'
def self.convert_data(elements)
results = []
if elements.is_a?(Array)
elements.each do |el|
results << deep_convert(el)
end
else
@hkraji
hkraji / gist:8093753
Created December 23, 2013 09:02
Turn off Git auto line fix
git config --global core.autocrlf false
@hkraji
hkraji / method_logger.rb
Created February 18, 2016 12:19
Module to be included / extended that wraps method calls
module MethodLogger
def self.extended(base)
clazz_methods = base.methods(false)
base.class_eval do
clazz_methods.each do |method_name|
original_method = method(method_name).unbind
define_singleton_method(method_name) do |*args, &block|
puts "$$---> #{base}##{method_name}(#{args.inspect})"
@hkraji
hkraji / weather.rb
Last active April 14, 2016 16:22
Improvement for gist https://gist.github.com/davefp/4990174 switching to Open Weather API
require 'net/http'
# you can find CITY_ID here http://bulk.openweathermap.org/sample/city.list.json.gz
CITY_ID = 2172517
# options: metric / imperial
UNITS = 'metric'
# create free account on open weather map to get API key
API_KEY = ENV['WEATHER_KEY']
@hkraji
hkraji / checkout
Last active December 25, 2017 13:38
Bash script to update or checkout needed git branches
#!/usr/bin/env bash
#
# Usage:
#
# checkout BRANCH_NAME
#
# checkout master
# checkout hkraji/pr_work_in_progress
#
@hkraji
hkraji / s3.rake
Created February 5, 2018 15:00
Connect to S3 and Create files
require 'rake'
require 'ap'
namespace :gazzda_s3 do
desc 'Upload images from directory to specified s3 bucket'
task :upload, [:bucket] do |t, args|
path_to_images = '/Users/haris/rails/scm_gazzda/image-files'
bucket = args[:bucket]
connection = Fog::Storage.new({ :provider => "AWS", :aws_access_key_id => ENV['AWS_KEY_ID'], :aws_secret_access_key => ENV['AWS_KEY_SECRET'], :region => 'eu-central-1' })
@hkraji
hkraji / nginx.conf
Created October 25, 2019 10:46
Nginx proxy configuration
files:
/etc/nginx/conf.d/proxy.conf:
content: |
client_max_body_size 500M;
server_names_hash_bucket_size 128;
upstream backend {
server unix:///var/run/puma/my_app.sock;
}
@hkraji
hkraji / README.md
Last active January 16, 2024 09:50
Data tables Rails Implementation (Backend)

Intro

Following are some code samples from one of the features I've developed on my startup Vorta. Vorta is Supply Chain Software and it has a LOT of tables. To support that we've used datatables since it was best solution at the time on the frontend. Since we needed support for large, floating tables.

The following backend-only code uses DSL to define a table. By simply defining CustomerDatatable, you get a functional table with sorting, searching, toggling, and reordering capabilities without any custom code. While there are additional supporting classes, I've only included a few. Despite its complexity, this approach simplifies maintenance and accelerates new development by confining changes to _datatable files, thereby hiding much of the complexity.

Video

To visually see what I mean you can view this video