George Opritescu

Developer from somewhere

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.

Read More

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
Read More

quick debugging in ruby when pry is not available

Insert the following statement where you’d like execution to stop:

require "debug"
Read More

executing external commands using lua

io.popen"pwd":read'*l'
Read More
lua

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</b> then, the following works too:

u = Repo.get(User, 1)
p = Repo.preload(u, :association_name)
Read More

phoenix generate model migration

mix phoenix.gen.model ExerciseEntry exercise_entries date:datetime exercise:string category:string weight:float reps:integer user_id:integer
Read More

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'
Read More

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
Read More

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.

Read More

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 :)
Read More