test

Origami Around
Acquired Stardust
2025 on Tumblr: Trends That Defined the Year

★
Keni
No title available
Xuebing Du

titsay

blake kathryn
we're not kids anymore.
h

Kiana Khansmith
$LAYYYTER

roma★
NASA
wallacepolsom
styofa doing anything
almost home
cherry valley forever

Janaina Medeiros
seen from United States

seen from United States
seen from United States

seen from Italy
seen from United States
seen from United States
seen from United States

seen from United States
seen from United States

seen from United States
seen from United States
seen from United States

seen from United States

seen from United States
seen from United States

seen from Germany
seen from United States
seen from United Kingdom

seen from Germany

seen from United States
@gazay
test
https://youtu.be/JhyzGDPwmYU
. #paintings #paint #painter #art #artist #color #draw #drawing #drawings #watercolor #people #artistz_united https://instagram.com/p/1DjFqUsFzj/ https://instagram.com/p/1DjFqUsFzj/
. #paintings #paint #painter #art #artist #color #draw #drawing #drawings #watercolor #people https://instagram.com/p/1Df6GEMF9B/ https://instagram.com/p/1Df6GEMF9B/
#paintings #paint #painter #art #artist #color #draw #drawing #drawings #oilpastels #watercolor #portrait #abstract #artistz_united https://instagram.com/p/1CnyoUsFxF/ https://instagram.com/p/1CnyoUsFxF/
Munk mood #paintings #paint #painter #art #artist #color #draw #drawing #drawings #watercolor #munk #face #portrait https://instagram.com/p/0_5Y8hsF4J/ https://instagram.com/p/0_5Y8hsF4J/
Singapore cafe #paintings #paint #painter #art #artist #color #draw #drawing #drawings #watercolor #cityscape https://instagram.com/p/0_4CrHsF2k/ https://instagram.com/p/0_4CrHsF2k/
Apple delivery #paintings #paint #painter #art #artist #color #draw #drawing #drawings #watercolor #fantasy https://instagram.com/p/0_4SgWMF2-/ https://instagram.com/p/0_4SgWMF2-/
The story how I used gon with rabl on groupon.ru
I've released a new version of my gem Gon (currently 4.0.0) recently, so I've decided to make some examples of it's features in use. This library can help you to simplify working with data in MVC architecture. It allows you to work with controller data from js without passing this data through view. Currently available are versions of gon for RoR applications, sinatra-like applications (sinatra, padrino, etc.) and for .Net MVC.
Map in admin section
I had a task to arrange Groupon offers by territory, which can be edited by administrator. These offers are shown to people, who live in desired territory, with higher priority comparing to other offers. I decided to make interactive map in admin section using Yandex.Maps, where admin would be able to set points and areas for each offer. Areas can be added and also edited, and than saved in database. Yandex.Maps offer a great API for drowing on maps, I choosed polygons for drowing areas and points with tooltips for offers. You can see here screenshot with areas, but without points - confidential information ;)
I created several data models: CityArea for description of the area in the city, CityAreaPoint as a base for storage of coordinates of points of which CityArea consists, and AreaOffer describing connection of the offer to the area. I've prepared a page, JS for drowing the areas, server logic for connection of objects, and then - then I had to decide how to output the data on the page. One of standart solutions for me in MVC - to choose necessary data in contreoller, to edit it to the right format, to write the end data massive to a variable and after all to add to view an element with data-attribute, where this data would be stored and then readed by JS. So I did somehow like this:
app/controllers/admin/map_controller.rb
@location = City.find(params[:city_id].to_i) @offers = Offer.sorted.by_city(@location).by_day(params[:date]) @offers.map! do |offer| points = offer.points.map do |point| { id: point.id, longitude: point.longitude, latitude: point.latitude } end { id: offer.id, permalink: offer.permalink, title: offer.short_title, points: points } end @city_areas = CityArea.find_by_city @location @city_areas.map! do |area| # the same as with offers end
app/views/admin/map/map.html.haml
.data-container{ data: { areas: @city_areas.to_json, offers: @offers.to_json } }
app/assets/javascripts/admin/map.js
$('.data-container').data('offers') ...
As a result we have a very dirty action in controller with too much of code that shouldn't be there. I can move this code to model, but it's not a good decision, too, because there is a clearer solution. I decided to use my own gem gon, which has support for ruby templating gems - rabl and jbuilder. I like rabl so much - great gem which works perfectly with collections of objects and associated AR objects, that's why code inside templates becomes more optimal, clear and easy understandable then if we format arrays with native ruby methods. And gon just allows us to use full power of rabl very easy:
app/controllers/admin/map_controller.rb
@location = City.find(params[:city_id].to_i) @offers = Offer.sorted.by_city(@location).by_day(params[:date]) @city_areas = CityArea.find_by_city @location gon.rabl template: 'app/rabl/offers.json.rabl', as: 'offers' gon.rabl template: 'app/rabl/areas.json.rabl', as: 'areas'
app/rabl/offers.json.rabl
collection @offers => 'offers' attributes :id, :permalink, :short_title child :points do attributes :id, :latitude, :longitude end
app/assets/javascripts/admin/map.js
gon.offers …
So, with minimal effort for transformation of the data and sending this data to JS, I get pretty "clean" controller action and arrays of needed data in JS.
Gon gem
In addition to work with templates of rabl and jbuilder gon is also perfect for sending some initial or global data, which assigns in any place of project and can be read in any place of project. So for example if value of some variable is to be present on each page of project - you can assign this variable in initializer. For doing this you should use method gon.global, which works like original gon, except scope of visibility of variables for gon.global is global :) In JS variables can be accessed through namespace gon.global.
Besides, couple of days ago I've released new version of gon gem - 4.0.0 which have a new functionality for renewing value of gon variable without reloading page (through ajax). This is gon.watch. New functionality allows to renew data as in loop with period n-miliseconds, as without looping, one time renewing for some event. I want to show one simple example of possibility to display the result of the linux top command in real time with couple of lines of code:
Let's start a new rails application. For displaying output of linux top command on page we should do the following six steps:
1. Add in Gemfile line gem 'gon' and run bundle install
2. Add controller with action for example 'home#foo', view for this action app/views/home/foo.html.erb and JS (or coffee or whatever) app/assets/javascripts/home.js.coffee
rails g controller home foo
3. In action of controller app/controllers/home_controller.rb assign gon.watch.top variable to output from one-time executing command `top -l1`
def foo gon.watch.top = `top -l1` end
4. In layout app/views/layouts/application.html.erb add in the head area call to helper include_gon with option watch:
<head> <%= include_gon(watch: true) %>
5. In view app/views/home/foo.html.erb add tag, which will display output of top command:
<pre style='font-family:monospace;'></pre>
6. In coffee-script file app/assets/javascripts/home.js.coffee add code which will be watch for variable and renew content of tag pre:
$(document).ready -> renewPre = (data) -> $('pre').html(data.replace(/\\n/, "\n")) gon.watch('top', interval: 1000, renewPre)
gon.watch accepts two or three parameters - name of variable, options (optional), and callback. In our case we send to gon.watch option interval: 1000 which will loop executing of code of gon.watch with period of 1 second. This means that each second gon.watch will do ajax request to controller action home#foo and return from it only new value of variable gon.watch.top. If the ajax request is successful - gon.watch will call callback function, which in our case is renewPre. This function will rewrite content of pre tag. For stoping execution of loop there is a function gon.unwatch, with accepts two parameters: name of variable and callback function. I think it's clear that if you don't use option interval with gon.watch function, there will be no loop. Only one time execution of gon.watch code - one ajax request and if successful - one time renewal content of tag pre.
That's it! Run rails s, go to 0.0.0.0:3000/foo and there you'll see live top like in terminal.
Why I monkeypatched Haml
If you don't know about great @kossnocorp project role and nice port of it for rails - go and open them for yourself :)
The story here is about my fork of role-rails for Haml.
It's all started when @kossnocorp wrote twit about role-rails where guys done great support for template engine slim through slim's possibility for adding custom shortcuts and attribute delimeter:
module RoleRails class Engine < ::Rails::Engine initializer "role-rails.register" do |app| if defined?(Slim::Parser) Slim::Parser.default_options[:shortcut].try(:[]=, '@', 'role') end if defined?(Slim::Engine) Slim::Engine.default_options[:attr_delimiter].try(:[]=, 'role', ' ') end end end end
In this twit Koss asked "who can do the same for Haml" and I thought - why not.
Differences of haml with slim are big (was a month ago - don't really know what situation is now):
Haml doesn't have native function and normal way to add new delimeters and shortcuts.
All predefined in Haml shortcuts were hardcoded with constants and regexps.
Engine functions which work with those shortcuts and regexps weren't changed from 2010.
Haml wasn't maintained about 4 months at moment when I did my gem
Again - it was a month ago, now I see that they work hard again on haml and I think now all should be ok and I need to improve my gem. And I want to note that I really respect open source guys who did such a great projects like Haml for everybody for free.
So I decided not to do pull request (because there were about 20-30 pulls from moment when they stop maintained master branch) and I should do a lot of changes in Haml structure, but I didn't had much time for this. I decided just to do monkey patch for Haml::Parser module. I changed three methods of it which work with shortcuts and attributes:
First was `process_line` method which analyzes first symbol of line. There is really simple logic - we match some pattern and do action for it. So I redefined this method with my matcher:
original_process_line_method = instance_method :process_line define_method :process_line do |text, index| if text[0] === DIV_ROLE push div(text) else original_process_line_method.bind(self).call(text, index) end end
Second was harder, because other methods were with hardcoded regexps and I can't just insert new condition inside them, so I was needed to rewrite them:
def self.parse_class_and_id(list) attributes = {} list.scan(/([#.@])([-:_a-zA-Z0-9]+)/) do |type, property| case type when '.' if attributes['class'] attributes['class'] += " " else attributes['class'] = "" end attributes['class'] += property when '#'; attributes['id'] = property when '@' if attributes['role'] attributes['role'] += " " else attributes['role'] = "" end attributes['role'] += property end end attributes end def parse_tag(line) raise SyntaxError.new("Invalid tag: \"#{line}\".") unless match = line.scan(/%([-:\w]+)([-:\w\.\#\@]*)(.*)/)[0] tag_name, attributes, rest = match raise SyntaxError.new("Illegal element: classes and ids must have values.") if attributes =~ /[\.#](\.|#|\z)/ new_attributes_hash = old_attributes_hash = last_line = nil object_ref = "nil" attributes_hashes = {} while rest case rest[0] when ?{ break if old_attributes_hash old_attributes_hash, rest, last_line = parse_old_attributes(rest) attributes_hashes[:old] = old_attributes_hash when ?( break if new_attributes_hash new_attributes_hash, rest, last_line = parse_new_attributes(rest) attributes_hashes[:new] = new_attributes_hash when ?[ break unless object_ref == "nil" object_ref, rest = balance(rest, ?[, ?]) else; break end end if rest nuke_whitespace, action, value = rest.scan(/(<>|><])?([=\/\~&!])?(.*)?/)[0] nuke_whitespace ||= '' nuke_outer_whitespace = nuke_whitespace.include? '>' nuke_inner_whitespace = nuke_whitespace.include? '<' end value = value.to_s.strip [tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace, nuke_inner_whitespace, action, value, last_line || @index] end
That's it. I checked it on couple of versions of Haml between 2010 and 2012 years and it works everywhere. So I can tell you that in many versions of Haml this monkey patch will works fine. Use my gem, use role - it's great together if you like rails, haml and role idea :)
Small note about git commit --amend and pull requests
I don't like when people make pull request with couple of thematic commits and then, after some core contributor tell them to fix something - they start to put more and more commits into branch for pull and as effects of it - into master of repo in which they want to do pull. And what commits. Typos. Rewritten algorithm. English fixes. And for each of them - different commit.
Very easy you can save your thematic structure of pull request. Lets imagine that you have pull request branch of `some_project` - `some_fixes_branch`. And in this branch you did three commits:
3. Last commit which does something with tests.
2. Commit in middle, which does something with docs.
1. First commit, which fixes code.
At first it is a great option for git commit: --amend. With this option you can merge current index of your repo with previous commit. It's equivalent to:
$ git reset --soft HEAD^ $ ... do something else to come up with the right tree ... $ git commit -c ORIG_HEAD
So in our case with three commits - with this option we can change without creating only last commit (#3) with tests:
$ ...make some changes in tests related to last commit... then you need add changed files to index $ git add . $ git commit --amend
Last command will show you your editor like if you did previous commit but with new changes. It will rewrite last commit and you should do force push to your pull branch to rewrite commit:
$ git push -f my_repo some_fixes_branch
But if you need to change #1 or #2 commit? There a many ways for that with git. But I prefer interactive rebase with branch on specific commit:
$ git log Then you choose that commit which you want to change and copy it's sha1 $ git rebase sha1\^1 --interactive btw sha1\^1 is for zsh. in bash you just write sha1^1 $ ...do things I described below about interactive mode of rebase... $ git add . $ git commit --amend $ git rebase --continue $ git push -f my_repo some_fixes_branch
In interactive mode of rebase you can do anything with commits which in rebase scope. For example edit :) Here how looks interactive mode:
Please enjoy and don't do pull requests with thousands of fixes instead of some cool needed commit.
Tonic gem. Create your gh-pages more pleasantly
When I just find that github gives possibility to create page for projects so easy as just create new branch and put there static html page named index.html - I was happy. When I find that you can use Jekyll for creating whole blog through this technology - my happiness grows twice. And finally when they did super feature that you can create gh-page with couple of clicks - it's just blown my mind)
But then I tried in one project, then in couple more. And I realized that I really miss my preferred technologies like Haml, Sass with Compass and Coffeescript. I started to research gems for this area - about creating gh-pages - and didn't find anything! I thought that was just because now it IS really easy to create some page for project. Really great job did GitHub team.
But for me and some of my friends it will be much pleased if we can create our pages with preferred technologies and friendly structure, similar to rails assets pipeline, if we can just run some server or observer in development which will compile for us all changes in files.
So I just started to do my lazy-gem (Tonic), which will do most part of creating gh-pages for me - creating new branch, removing all data from this branch, copy template for developing static page without building files after each change, commit and push to github of course.
At first I was needed a good, light and easy to configure static site generator with technologies which I mentioned before. So I didn't do some research, I just wrote another bicycle on base my bro's @andrey_sitnik project easings.net. Many days after that I found cool gem middleman and added support for it in tonic.
Then I was needed to implement working with git. So at first I decided to use @defunkt's github-gem, but there wasn't functionality that I needed and I just look how they implement it. So I just get from there class Shell, which is simple implementation of executing shell command in background with possibility to debug errors.
After that I just stuck at writing specs because I want to check functionality at all, not just right written ruby code. So I did some trick to initialize git repository in spec folder in before filter, remove this repo in after filter and run execution of gem functionality from new repo's directory:
describe Tonic do context 'Tonic will' do context "create gh-pages and" do before :all do unless Dir.pwd =~ /spec\/dummy_git_repo/ command = <<EOF cd spec/dummy_git_repo;\ git init;\ git add .;\ git commit -am 'init commit';\ rspec ../../ EOF exec command end end # some specs after :all do if Dir.pwd =~ /spec\/dummy_git_repo/ `rm -rf .git` exec 'cd ../..' end end end end end
After hours of debugging and checking I finally pushed beta-version for testing. I think it turned out great! My next step is injecting README from master branch into some partial or just html which easily can be included in page.
I hope someone will enjoy working with my gem as I do :)
I'm vimer and I'm proud of it
When I just started use ruby (I was about 4 years C# programmer - I started programming in this language) I was really jealous to my friends who use macbooks. Because there was a lot of posts about HOW COOL TEXTMATE IS for ruby developers. At first when I was working on big software corporation as junior C# programmer and there were a lot of bureaucracy in development process and a lot of free time and my friends opened the ruby world for me - I tried to use some IDEs like NetBeans and Eclipse (because I was really dependent on IDE style development) for writing ruby code. Then I saw how my friends just write cool stuff in "just notepad" - textmate and I tried to use notepad++. But then I bought my first macbook and was really happy because of textmate. So nice highlighting, bundles and etc. I like that time - it was just beginning for me as ruby programmer, in that time I started to read a lot of posts, books and try to write my own gems and applications for customers and for my study.
And all this time I was fascinated by romantic of Linux and it's tools. And I heard and read many good reviews about text editors vi, vim, emacs. How they can help you to improve your speed of working with code, text and scripts. But when I tried to switch - I just spent about couple of days for it and throw it out.
Now I can just clap my hands to two great guys who started work on janus project. This is a great idea for ruby world, for ruby community, for people who stuck on textmate and wants more then it can give - just make intermediate option for that people. Give all power of vim and make the switch not so painful, than if you try do it with empty standart vim. Almost all possibilities of textmate that guys put in this project. You need only install like they describe in README and start to use. You don't even need to know about different modes of vim, you can use mouse as before, your shortcuts and many more things but based on vim power.
I switched to vim about eight months ago and I enjoyed every second of editing text, code and scripts in this editor. Of course I didn't use now mouse, I saw many screencasts, read a lot of posts and manuals about vim and I every day open for myself something new in this great flexible tool. I did my own assemble of plugins instead of janus, I wrote several functions which helps me in my everyday work, my own shortcuts. But janus was very important step for me in switching to vim - I don't spent time to understand how to do something in different modes and hotkeys when I was on work, I just used all what I learned from vimtutor and from textmate together. And in the night I read something, tried something vim-way and admire how much easier and more enjoyable to do so with some simple commands or options then old way.
P.s. I can write and talk about vim and how it's cool to use it infinitely, and I think I will post here some cool tools which I use, but I should point one of greatest plus of vim for me - it presents on each linux server. If not vim then vi or less, where you can do almost the same things as in vim.
Install ruby-debug19 with new rvm architecture
Many months ago I started using in my projects ruby 1.9.3 and in the first day I get problem with ruby-debug19. It's described in @spastorino's team blog post ruby 1.9.3 and ruby-debug. All was ok when I tried it then, but now, when I loose my old macbook air because of indonesian rains (sad but true) and bought new one without any possibilities to get backup from old one, I have had again problem with installing ruby-debug19. I tried to use methods described in comments of Santiago's post, but it doesn't help. Now I can't find sources of ruby in rvm directories and after some time I asked @brainopia about this problem. He gave me this script:
#!/bin/sh rvm_current=`rvm current` echo "Installing ruby-debug with $rvm_current ..." curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem ruby-debug19 -- --with-ruby-include=$rvm_path/src/$rvm_current rm linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem echo "Done."
All installed without any problems! The problem was in new place for ruby sources in rvm directories, now they all stores in /Users/username/.rvm/src/ .
And before, in earlier versions of rvm, ruby sources were separately in their own directories: /Users/username/.rvm/rubies/ruby-1.9.3-p0/include/ruby-1.9.1/ruby-1.9.3-p0/
Something about code styles
Several months ago we with my brogrammer @brainopia talked about style of assignation, when expression very long and complex. So here some examples of what we thinking:
# Original example - method chain @authors = Author.alive.now_and_future.common_and_side.location(@location).all( :select => 'permalink as not_delegated_permalink', :group => :permalink, :having => 'count(*)=count(distinct placement)' + 'and bool_or(on_sale_from <= current_date)' )
This is how usually people write code. Conventions about 80 symbols, parameters each per line, and long and complex method chain.
So @brainopia proposed to me several variants how we can rewrite this code for more readability.
# Add more readability for methods @authors = Author. alive. now_and_future. common_and_side. location(@location). all( :select => 'permalink as not_delegated_permalink', :group => :permalink, :having => 'count(*)=count(distinct placement)' + 'and bool_or(on_sale_from <= current_date)' )
Now looks easier to understand for me. I have problem with reading long and many times related to other files one-liners. So this variant more acceptable for me then original one. But here I don't like two moments:
indentation of start object differs with methods which we call on it
round brackets around the attributes of method 'all'
And here we have two options. First thing is that we can use escaping character and besides everywhere where we feel bad:
# Using escaping character @authors = \ Author. alive. now_and_future. common_and_side. location(@location). all \ :select => 'permalink as not_delegated_permalink', :group => :permalink, :having => 'count(*)=count(distinct placement)' + 'and bool_or(on_sale_from <= current_date)'
Looks better? Yeah, but indentation still not good for object - just move lines below it for one more softtab.
And the second option - we can move lines until we feel good about indentations and round brackets:
# Using indentation @authors = Author. alive. now_and_future. common_and_side. location(@location). all( :select => 'permalink as not_delegated_permalink', :group => :permalink, :having => 'count(*)=count(distinct placement)' + 'and bool_or(on_sale_from <= current_date)' )
We discussed about this options a lot, but I think here each programmer choses what he prefers. Now I understand that I want to use mostly variant with escaping character, because for me it is now better then others by some points:
you don't have problem with long attributes and 80-symbols convention how could arise in last example with large indentations
you can look fast on all methods in chain separately and on all their attributes
it's just looks good for me ;)
But code style in product code for some projects I work don't support this notation and maybe it will be little uncomfortable problem for someone I work with to read it. So in most cases when I can't refactor this big method chain in some reasons - I use mostly notation like in original example.
P.s. Sorry about english. I don't care. Me you BORSCH. ಠ_ಠ