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 / gc.rb
Last active September 22, 2015 09:33
script for git commit with preview of file changes, last 5 commits and enforcing of ticket prefix
#!/usr/bin/env ruby
require 'open3'
require 'colorize'
unless Dir.exists?('.git')
puts 'No .git directory'.red
exit
end
@dux
dux / template.js
Last active August 29, 2015 14:24
Super simple JavaScript prototype templateing
// simple templateing
String.prototype.template = function() {
var formatted = this, arg;
var args = typeof(arguments[0]) === 'object' ? arguments[0] : arguments;
for(arg in args) {
formatted = formatted.replace("{" + arg + "}", args[arg]);
}
return formatted;
};
@dux
dux / sortable.html
Last active August 29, 2015 14:25
Best Sortable and Draggable
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sortable test Dino</title>
</head>
<body>
<style>
ul { margin:0; padding:0; width:200px; float:left; margin-right:50px; }
ul li { border:1px solid #ccc; background-color:#eee; margin-bottom:10px; padding:10px; }
@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; }
# 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'
# ]
class Runner
@threads = {}
def self.spawn(name, ttl=1)
@threads[name] = {}
Thread.new do
while @threads[name]
yield(@threads[name])
sleep ttl
end
@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'
require 'benchmark'
require 'haml'
require 'tilt'
Tilt.register Haml::Engine, 'haml'
class Template
attr_reader :response, :locals
@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
@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__