Skip to content

Instantly share code, notes, and snippets.

@kelso
kelso / campaigns_controller_spec.rb
Last active August 29, 2015 13:56
Testing controller with RSpec - sample.
require 'spec_helper'
describe CampaignsController do
let(:user){ create(:admin_user) }
before(:each) do
sign_in user
end
describe "GET #index" do
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT price, product_id FROM product_attributes");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "price: ".$row[0]
echo "product_id".$row[1]
}
git init .
git add .
git status
git commit -a -m "Popis commitu"
git log
git push
git pull
------
@kelso
kelso / heroku-deploy.txt
Created April 27, 2015 17:51
Deploy Rails aplikácie na Heroku s pg gemom
# Instalacia Heroku Toolbelt:
# https://toolbelt.heroku.com
heroku login
# Install postgres on local machine:
http://postgresapp.com
# and run:
http://bit.ly/1kBJJi2
@kelso
kelso / albums_controller.rb
Created June 10, 2015 11:43
Groupovanie podla rokov
@albums = Album.all(:conditions => ['published = ?', true], :order => 'created_at desc')
@albums_years = @albums.group_by { |a| a.created_at.beginning_of_year }
# group_by je tu klucovy, vsimni si ze sablona index potom pouziva tu premennu @albums_years
# Tie :conditions je samozrejme zastarala syntax,
# ale aj tak tebe bude stacit Album.all, resp Album.page(...) v pripade strankovania cez kaminari
def fancy(str)
str = str.gsub(/[ ]+/," ")
str = str.gsub(/ /,"-")
str = str.downcase
str = str.mb_chars.normalize(:kd).gsub(/[^\-x00-\x7F]/n, '').to_s
return str
end
# Pole s polozkami
@menu_items = [
['messaging', messagging_path, 'Zpravy'],
['admin', admin_path, 'Administrace']
]
# Generator menu
# potrebujeme uzivatela v pravidelnych intervaloch udrziavat "pri zivote"
# musime mu teda niekde aktualizovat cas poslednej aktivity
# pomocou before filtra to docielime pri kazdom prekliku aplikaciou
# umiestnit do kazdeho controlleru, kde potrebujeme
before_filter :do_last_act
# application.rb
@kelso
kelso / seeds.rb
Created September 30, 2015 11:54
default user seed
# Default user
email = 'demo@demo.sk'
password = 'demodemo'
unless User.exists?(email: email)
User.create!(email: email, password: password, password_confirmation: password)
end
@kelso
kelso / gist:1852574
Created February 17, 2012 10:40
brew
$ brew install mysql
==> Installing mysql dependency: cmake
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/cmake-2.8.7-bottle.tar.gz
######################################################################## 100.0%
==> Pouring cmake-2.8.7.bottle.tar.gz
Warning: m4 macros were installed to "share/aclocal".
Homebrew does not append "/usr/local/share/aclocal"
to "/usr/share/aclocal/dirlist". If an autoconf script you use
requires these m4 macros, you'll need to add this path manually.
==> Summary