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:1674131
Created January 25, 2012 01:55
Sass / Less / Coffee compiler - Ruby command line
#!/usr/bin/env ruby
# sudo gem install sass
# npm install less -g
# npm install coffee -g
p 'Dux sass/less/coffee compiler v0.1'
while true
sleep 1 if (@last_mtime ||=0) > 0
@dux
dux / gist:1827509
Created February 14, 2012 15:18
JavaScript image reseize and crop, inline-onload, imgur.com optimized
window.resize_crop = (img) ->
org = new Image()
org.src = img.src
org.onload = ->
j_img = $(img)
src = @src
img_w = parseInt j_img.css "width"
@dux
dux / gist:2147691
Created March 21, 2012 14:43
Paperclip - resize default image if image provided for asset manager
:styles => lambda { |i| i.instance.file_content_type =~ /image/ ? { :original => "800x600>" } : {} }
@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
@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: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('acc@gmail.com', 'pass')
inbox = gmail.mailbox('inbox')
@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: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: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: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;