Skip to content

Instantly share code, notes, and snippets.

@nirname
nirname / notifier.rb
Last active July 10, 2018 12:29
Send email through ApplicationMailer with file attachments from ActiveStorage
response.docs.each_with_index do |doc, i|
attachments[doc.filename.to_s] = {:mime_type => doc.blob.content_type, :content => doc.blob.download }
end
@nirname
nirname / stdin.sh
Created August 8, 2016 17:29
Read stdin in shell
myvar=`cat`
echo "$myvar"
@nirname
nirname / sqlformat.sh
Last active August 8, 2016 17:29
Using `sqlformat` for pgAdmin3
#!/bin/bash
/usr/local/bin/sqlformat --keywords upper --reindent --identifiers lower -
@nirname
nirname / .gitconfig
Last active November 25, 2015 08:03
Git comparison with meld
[diff]
external = /home/user/diff.py
@nirname
nirname / options.coffee
Last active November 25, 2015 08:06
Catch list of parameters in function
// coffescript
(options...)->
$.each options, (i, v)->
console.log v
@nirname
nirname / superkiller.js
Created November 10, 2015 15:40
Recursivly remove property by name
function superkiller(o, prop_name) {
if(o.hasOwnProperty(prop_name)) {
delete o[prop_name]
}
$.each(x, function(i, e) {
if(typeof(e) == "object") { superkiller(e, prop_name) }
});
}
@nirname
nirname / escape.rb
Created April 24, 2015 10:52
Escape HTML and split user text from text_area to display
h.simple_format h.h(object.text)
@nirname
nirname / delegate_all.rb
Created April 19, 2013 12:16
Delegates all method to target
def method_missing(method_name, *arguments, &block)
return target.send(method_name, *arguments, &block) if target.respond_to? method_name
super
end
@nirname
nirname / boolean.rb
Last active December 12, 2015 07:39
Condition with array of predicated
[true, false].reduce(&:&)
[true, false].reduce(&:|)
# the same
[true, false].any?
@nirname
nirname / unique.coffee
Last active December 11, 2015 07:08
Making a unique javascript array using JQuery
if Array.prototype.unique == undefined
Array.prototype.unique = ->
filtered_array = []
$.each this.sort(), (index, value)->
filtered_array.push(value) if filtered_array.indexOf(value) == -1
filtered_array
if Array.prototype.is_unique == undefined
Array.prototype.is_unique = ->
this.length == this.unique.length