capybara login with user scope
If you have more than one user type, you can login as it from your tests using:
login_as(your_user, :scope => :admin)
The example above assumes that you also have an admin mapping, besides your User mapping.
performing a count operation in ecto
iex(3)> import Ecto.Query
nil
iex(4)> Repo.all(from f in User, select: count(f.id))
[debug] SELECT count(u0."id") FROM "users" AS u0 [] OK query=67.8ms queue=10.5ms
[1]
or alternatively:
iex(5)> Repo.one(from f in User, select: count(f.id))
1
[debug] SELECT count(u0."id") FROM "users" AS u0 [] OK query=0.6ms
quick debugging in ruby when pry is not available
Insert the following statement where you’d like execution to stop:
require "debug"
preloading associations in elixir
Repo.get(User, 1) |> Repo.preload(:association_name)
or, if an association has not been loaded, and you receive: #Ecto.Association.NotLoaded
u = Repo.get(User, 1)
p = Repo.preload(u, :association_name)
phoenix generate model migration
mix phoenix.gen.model ExerciseEntry exercise_entries date:datetime exercise:string category:string weight:float reps:integer user_id:integer
extracting a range of lines from a file
sed -n 10000,20000p initial_file.log > smaller.log
and to print all the lines after a specific line number:
sed -n '10000,$p'
viewing an opsworks logfile
Noticed that sometimes viewing the log from the webpage does not work. This allows you to see once you’re logged into the box:
opsworks-agent-cli show_log
ruby each_with_object
each_with_object has the same effects as an inject, just the parameter order is reversed, each_with_object has (element,accumulator), and you don’t need to return the object.
linx no.11
- [Remote Control Server] (https://github.com/jeremija/remote-control-server) allows you to easily control your PC through a browser. Really useful for reading a book on a big HDMI connected TV :)