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 / 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

@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 / 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 / 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 / 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 / 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})"
require 'puppet'
puppet_params = {
:name => 'foo',
:ensure => 'present',
:key => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDH1chpGVgtqgdXh62qS1V2g8Ic2nbpfXgzXAseObYYocOa0NIeCOmFxbMEhzT9h6/EhYTpF6tq0Gn8aBBd8gb90OlHdTIZ2j9IVhqLxmwnUJ3lwTbq6cEdVy1M/TM+A/TygRcqRrbNgoswGaVem
lfk7caeenN2KxG3vjzq5cCIAhGD7DeI9qQawZuKdJOCOgqUL6rF/J9nyyzPAS5uCeQumncGR+cfrywe9ZCUJrUbrWeYFHtB0d3XhbxCYJIqui3kMmbhQzsLGka9tcWQ1Zwm7VpcIrgerEyHO+0aNusG1szvxQkVWk1Bi7RI8fNLaogSq+HqkU2CRH
nEk7arJa9t',
:type => 'ssh-rsa',
:user => 'ubuntu'
@hkraji
hkraji / Test.java
Created August 17, 2015 11:44
Za Kerima
import java.io.File;
import java.io.FileFilter;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(searchFile("test.pp", new File("/Users/haris/r8")));
@hkraji
hkraji / remove_ssh.ruby
Created April 17, 2014 11:03
Remove ssh keys for dtk client
output = `dtk account list-ssh-keys`
output = output.split(/\n/)
output.each do |line|
match = line.match(/[0-9]+ \| (.*) \|/)
if match
identifier = match[1]
puts "Deleting #{identifier} ..."
puts `dtk account delete-ssh-key #{identifier}`
end
@hkraji
hkraji / got.rb
Created March 20, 2014 12:05
Random Generation for GOT board game
houses = ['Lannister','Stark','Grayjoy','Baratheon','Tyrell','Martel']
players = ['Nera','Asaf','Keno','Aki','Haris','Zaharije']
while !houses.empty? do
puts "#{players.delete_at(rand(players.length))} :: #{houses.delete_at(rand(houses.length))}"
end