Skip to content

Instantly share code, notes, and snippets.

View dux's full-sized avatar

Dino Reić dux

  • Trifolium
  • London, Zagreb, Berlin
View GitHub Profile
@dux
dux / aws_s3.rb
Last active September 14, 2016 09:29
AWS S3 local file or URL upload
require 'aws-sdk'
require 'json'
require 'digest'
['AWS_REGION', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'].each { |key|
next if ENV[key]
puts "ENV key '#{key}' not defined (AwsS3)"
exit
}
@dux
dux / geocode-bounding-box.rb
Created August 1, 2016 14:56
geocode-bounding-box
require 'geocoder'
point = [48.1293696,11.5783119]
puts Geocoder::Calculations.bounding_box point, 100, :unit=>:km
@dux
dux / Rakefile
Created April 9, 2016 12:27
adds menu choser to default rake task
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Webapp::Application.load_tasks
### Custom
Rake::Task["default"].clear
@dux
dux / annotations.rb
Created January 19, 2016 07:41
Java style annotations in Ruby
module Annotations
def annotations(meth=nil)
return @__annotations__[meth] if meth
@__annotations__
end
private
def method_added(m)
(@__annotations__ ||= {})[m] = @__last_annotation__ if @__last_annotation__
@dux
dux / sequel.rb
Last active December 5, 2015 22:37
add before_save and after_save filters to sequel
output
validate
before save BASE
before save MODEL
after_save MODEL
require 'benchmark'
require 'haml'
require 'tilt'
Tilt.register Haml::Engine, 'haml'
class Template
attr_reader :response, :locals
@dux
dux / auto-migrate - run this files, rest 2 should be includes
Last active October 1, 2015 12:06
Ruby ActiveRecord auto migrations without Rails, standalone
#!/usr/bin/env ruby
require './scripts/lib/auto_migrate.rb'
db_config = YAML.load_file('./config/database.yml')[ENV['RACK_ENV'] || 'development']
AutoMigrate.connect(db_config)
require './config/schema.rb'
class Runner
@threads = {}
def self.spawn(name, ttl=1)
@threads[name] = {}
Thread.new do
while @threads[name]
yield(@threads[name])
sleep ttl
end
# html = render.tag 'head', ->
# [
# @h1 class:'test', -> @tag('small', 'product') + 'Dux'
# @div ->
# [2,4,6,7].map (el) =>
# @li el
# @tag '.bla.blo', 'div.bla'
# @tag '#bla.klass', 'div id bla'
# ]
@dux
dux / drag-drop.html
Created July 17, 2015 13:57
Simple native + jQuery drag and drop
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Native drag drop</title>
</head>
<body>
<style media="screen">
div.elms .item { width:100px; border:1px solid #ddd; background:#eee; padding:5px; margin-bottom:5px; }
div.targets { margin-top:100px; }