Skip to content

Instantly share code, notes, and snippets.

Avatar

Haris Krajina hkraji

  • Cron
  • Sarajevo, Bosnia and Herzegovina
View GitHub Profile
@hkraji
hkraji / nginx.conf
Created Oct 25, 2019
Nginx proxy configuration
View nginx.conf
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 Feb 5, 2018
Connect to S3 and Create files
View s3.rake
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 Dec 25, 2017
Bash script to update or checkout needed git branches
View checkout
#!/usr/bin/env bash
#
# Usage:
#
# checkout BRANCH_NAME
#
# checkout master
# checkout hkraji/pr_work_in_progress
#
@hkraji
hkraji / weather.rb
Last active Apr 14, 2016
Improvement for gist https://gist.github.com/davefp/4990174 switching to Open Weather API
View weather.rb
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 Feb 18, 2016
Module to be included / extended that wraps method calls
View method_logger.rb
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})"
View example_puppet.rb
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'
View Test.java
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 Apr 17, 2014
Remove ssh keys for dtk client
View remove_ssh.ruby
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 Mar 20, 2014
Random Generation for GOT board game
View got.rb
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
@hkraji
hkraji / utf8_normalization.rb
Created Mar 19, 2014
Normalize to UTF8 (remove invalid utf8 characters)
View utf8_normalization.rb
#
# Takes possible invalid UTF-8 output and ignores invalid bytes
#
# http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
def self.normalize_to_utf8_output(response)
if response[:data]
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
output = response[:data][:output]||''
valid_output = ic.iconv(output + ' ')[0..-2]