Skip to content

Instantly share code, notes, and snippets.

View almaron's full-sized avatar

Ilya Levin almaron

View GitHub Profile
@almaron
almaron / gist:d7da253e32115851f33f
Last active August 29, 2015 14:02
Jbuilder setting values in array loop
# Can I do something like this?
%w(text_field, another_text_field, some_more_text).each do |field|
json.field simple_format(@item.send(field.to_sym)
end
# Instead of this
json.text_field simple_format(@item.text_field)
json.another_text_field simple_format(@item.another_text_field)
json.some_more_text simple_format(@item.some_more_text)
@app.factory 'ArrayService', ->
{
findInArrayBy: (array, index, value) ->
flag = false
angular.forEach array, (item, key)->
if item[index] == value
flag = true
flag
}
class GuestPost < ActiveRecord::Base
require 'rails_autolink'
validates_presence_of :head, :content, :user
def apply_answer(answer=nil)
if answer.present?
@answer = auto_link(answer)
end
Bootstrapping Chef...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15934 100 15934 0 0 37877 0 --:--:-- --:--:-- --:--:-- 95413
Downloading Chef 11.12.0 for el...
downloading https://www.opscode.com/chef/metadata?v=11.12.0&prerelease=false&nightlies=false&p=el&pv=6&m=x86_64
to file /tmp/install.sh.11766/metadata.txt
trying curl...
url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.0-1.el6.x86_64.rpm
md5 3e4fadc93e3080ec0b2ed811f36cb8bc
Bootstrapping Chef...
DEBUG: Initial command uname -s
DEBUG: Initial command sudo -V
DEBUG: Running processed command sudo -V
DEBUG: sudo -V stdout: Sudo версия 1.8.6p3
Параметры настройки: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --prefix=/usr --sbindir=/usr/sbin --libdir=/usr/lib64 --docdir=/usr/share/doc/sudo-1.8.6p3 --with-logging=syslog --with-logfac=authpriv --with-pam --with-pam-login --with-editor=/bin/vi --with-env-editor --with-ignore-dot --with-tty-tickets --with-ldap --with-ldap-conf-file=/etc/sudo-ldap.conf --with-selinux --with-passprompt=[sudo] password for %p: --with-linux-audit --with-sssd
DEBUG: sudo -V stdout: Sudoers policy plugin version 1.8
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end
guard 'rails' do
group :development, :test do
gem "rspec-rails"
gem 'rb-inotify', '~> 0.9'
gem "factory_girl_rails"
gem "capybara"
gem "guard-rspec"
gem "guard-rails"
gem "guard-livereload"
gem "rack-livereload"
end
//The HTML setup
<div ng-init="loadPhotos" ng-controller="PhotosCtrl" class="main_wrap"></div>
//The controller
PhotosCtrl = ($scope, $resource) ->
AllPhotos = $resource("/photos",{})
@ModelsCtrl = ($scope, $resource) ->
//resource
Import = $resource("/models/:model_id/import_photos",{model_id: '@model_id'},{push: {method: "POST", isArray:true}})
//function
$scope.importPhotos = (url) ->
photos = Import.push({model_id: $scope.model.id, url: url}, ->
$scope.model.photos.concat(photos)
)
$scope.import = {}
$scope.importPhotos = function(url) {
var photos;
photos = Import.push({
model_id: $scope.model.id,
url: url
}, function() {
$scope.photos.concat(photos);
});
$scope["import"] = {};