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: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 / 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: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 / git-stat.rb
Last active August 29, 2015 13:56
Simple git statistics, prints git user and number of files and lines changed in last 14 days
#!/usr/bin/ruby
require 'colorize'
require 'optparse'
options = {}
op = OptionParser.new do |opts|
opts.banner = "Usage: git-stat.rb [options]"
opts.on("-d", "--days N", Integer, "In last x days") do |v|
options[:days] = v
@dux
dux / generate.rb
Last active August 29, 2015 13:57
Simple native rails generate, without Rails and Rails generators
#!/usr/bin/ruby
require 'colorize'
@locations = []
def generate_file( file_name, data )
if File.exist?(file_name)
info = 'exists'.red
else
@dux
dux / expand_yt_to_fs.js
Last active August 29, 2015 13:57
Expand YouTube video to full screen - bookmarklet
// GOOD bookmarklet, copy and paste
javascript:elms=['masthead-positioner-height-offset', 'content', 'footer-container', 'masthead-positioner'];for (i in elms) { var e=document.getElementById(elms[i]); if (e) e.parentNode.removeChild(e); };document.getElementById('player-api').setAttribute('class','player-api');window.exTFS=function(){ s = document.body.clientHeight-1; document.getElementById('player-api').setAttribute('style','position:absolute;top:0px; left:0px; width:100%; min-height:'+s+'px;z-index:100000000000');document.getElementById('movie_player').setAttribute('style','min-height:'+s+'px;');void(document.getElementsByTagName('video')[0].setAttribute('style','width:100%;min-height:'+s+'px;'))};window.onresize=exTFS;exTFS();
// annotated source
elms=['masthead-positioner-height-offset', 'content', 'footer-container', 'masthead-positioner'];
for (i in elms) { var e=document.getElementById(elms[i]); if (e) e.parentNode.removeChild(e); }
document.getElementById('player-api').setAttribute('class','player-
@dux
dux / gist:9881717
Created March 30, 2014 23:30
get remote postgree database
#!/bin/bash
REMOTE_HOST=deployer@1.2.3.4
REMOTE_DB_NAME=db_production
REMOTE_DB_USER=db_user
REMOTE_DB_PASS=db_pass
LOCAL_DB=db_local
echo $REMOTE_DB_PASS | pbcopy
@dux
dux / finds.rb
Last active August 29, 2015 14:00
grep -r CLI response prettifier and open file inteface # http://i.imgur.com/qpNl0KQ.png
#!/usr/bin/ruby
find = ARGV.join(' ')
unless find =~ /\w/
print "WHAT: Finds text via grep -r, trims long reponses, pretty print and open file interface\n"
print "USAGE: ./finds [text to find in realtive path without quotes]\n"
print "EXAMPLE: ./finds def avatar\n"
print "@dux 2014\n"
exit
@dux
dux / cgrep
Created April 30, 2014 00:40
colorized grep # memcached -vv 2>&1 | cgrep GET SET # for resoult of http://i.imgur.com/ifnrEj9.png
#!/usr/bin/ruby
require 'colorize'
colors = [:green, :red, :yelow, :blue]
$stdin.each_line do |l|
for el, i in ARGV.each_with_index
next unless l =~ /#{el}/
print l.send(colors[i])
@dux
dux / string_base.rb
Last active August 29, 2015 14:03
Encode any integer to string base of choice. Just replace keys with one you want to encode into. StringBase.encode(11111111) == "frgh"
module StringBase
KEYS = 'bcdfghjklmnpqrstvwxyz'
def self.encode( value )
ring = Hash[KEYS.chars.map.with_index.to_a.map(&:reverse)]
base = KEYS.length
result = []
until value == 0
result << ring[ value % base ]
value /= base