Skip to content

Instantly share code, notes, and snippets.

tail -f log/production.log
@Olefine
Olefine / dump_rails
Created April 2, 2013 10:01
аналог vur_dump в php
puts YAML::dump(object)
@Olefine
Olefine / dominant colors
Last active December 15, 2015 22:59
dominant colors
require 'RMagick'
TOP_N = 10 # Number of swatches
# Create a 1-row image that has a column for every color in the quantized
# image. The columns are sorted decreasing frequency of appearance in the
# quantized image.
def sort_by_decreasing_frequency(img)
hist = img.color_histogram
# sort by decreasing frequency
@Olefine
Olefine / preview
Last active December 16, 2015 07:59
Add image preview without upload an image
function readURL(input, i) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e){
var image_tag = document.createElement('img');
$(image_tag)
.attr('src', e.target.result)
.width(100)
@Olefine
Olefine / search_methods
Created May 17, 2013 13:17
search_methods by method name
grep(/function/)
@Olefine
Olefine / json
Created May 21, 2013 11:14
json ajax rz2
$(document).ready ->
$('div#reload_form form').submit (event) ->
event.preventDefault()
form = $(this)
url = form.attr('action')
ammo = $('#ammo_to_reload').val()
$.ajax
type: 'put'
url: url
@Olefine
Olefine / lambda
Last active December 17, 2015 16:58
lambda expiriments
l = lambda do |string|
if string == "try"
return "There's no such thing"
else
return "Do or do not."
end
end
puts l.call("try")
@Olefine
Olefine / class_method.rb
Created May 24, 2013 13:54
another way create class methods in ruby
class Item
class << self
def show
puts "Class method show invoked"
end
end
end
@Olefine
Olefine / zip.rb
Created May 27, 2013 09:45
zip arrays
(1..5).to_a.zip (5..10).to_a
#=> [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]
@Olefine
Olefine / few2last.rb
Created May 27, 2013 09:50
last elemnts in array using slice and join into string using |
def few2last(array)
array.slice(-2..-1).join("|")
end