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 / gist:6300577
Created August 21, 2013 21:36
basic HAML filter to enable Html XMP tag functionality in IE and Opera :xmp
module Haml::Filters::Xmp
include Haml::Filters::Base
def render(text)
text.gsub /</, '&lt;'
end
end
@dux
dux / memento.jquery.coffee
Created August 15, 2013 22:05
Memorize jQuery and DOM init states
$.memento = (func) ->
if typeof func == 'function'
console.log '$.memento :store'
$.memento_stack ||= []
$.memento_stack.push func
$ -> func()
unless func
console.log '$.memento :reattach'
setTimeout ->
@dux
dux / gist:6207234
Last active December 20, 2015 22:48
Simple routed pjax
@Pjax =
skip_on: [],
push_state: false,
load_is_safe: false,
refresh: (func) -> Pjax.load(location.pathname+location.search, { func:func, no_scroll:true })
init: (@full_page=false) ->
return alert "#full_page ID referece not defined in PJAX!\n\nWrap whole page in one DIV element" unless @full_page
if window.history && window.history.pushState
@dux
dux / gist:5973588
Created July 11, 2013 08:27
MySQL set time zone
SET GLOBAL time_zone = '+2:00'; # global
SET time_zone ='+2:00' # session
SELECT @@global.time_zone, @@session.time_zone;
@dux
dux / gist:5973394
Last active December 19, 2015 14:59
nginx SSL common installation
# install openssl
sudo apt-get install openssl
# cd to certs folder, create if necessary :)
cd /etc/ssl/certs
# gen key
openssl genrsa -out websitename.key 2048
# gen csr and upload file content to SSL issuer
@dux
dux / gist:5343545
Last active December 15, 2015 23:50
labels checkboxes and gives them state, jquery plugin
# plugin cheeckbox label state
window.checkboxLabel_do = (el, on_, off_) ->
if el.is(":checked") then el.next().html(on_).css({color:'#080'}) else el.next().html(off_).css({color:'#800'})
$.fn.checkboxLabel = (on_, off_) ->
on_ ||= "ON"
off_ ||= "OFF"
@each ->
el = $(this)
@dux
dux / gist:5262359
Created March 28, 2013 11:00
safe rails for replacement. on runtime error, reports error and object, does not brake the application
def sfor(list, &block)
for el in list
begin
yield(el)
rescue
concat(%[<div style="background-color:#fdd; padding:4px; border:1px solid #ccc;"><ul><li>Object: #{}#{el.as_link rescue '-'} (#{el.class.name})</li><li>Error: #{$!}</li></ul></div>])
end
end
end
@dux
dux / gist:4507955
Last active December 10, 2015 23:18
read Gmail email like a boss
# https://github.com/mikel/mail
require 'rubygems'
require 'gmail'
require 'mail'
gmail = Gmail.new('[email protected]', 'pass')
inbox = gmail.mailbox('inbox')
@dux
dux / gist:2760251
Created May 21, 2012 01:53
Simple CSV class
#!/usr/bin/env ruby
# Hotel - broj ratinga - rating - datum - soba1 opis - soba1 cijena - soba2 opis soba 2 cijena
require 'rubygems'
require 'digest/md5'
require 'pp'
class Csv
attr_accessor :head, :data
@dux
dux / gist:2346537
Created April 9, 2012 21:06
cloudero connect
class ApplicationController < ActionController::Base
before_filter :cloud_token
protected
def cloud_token
ct = params[:cloud_token] || return
url = "http://cloud.trifoliumdoo.com/token/#{ct}"
begin