George Opritescu

Developer from somewhere

set a custom buildpack for heroku

For example, setting typescript as your buildpack:

heroku buildpacks:set https://github.com/pk11/heroku-buildpack-typescript.git -r heroku
Read More

recompile module from iex

Type this from iex, where NameOfModule is your module name:

r NameOfModule
Read More

production debugging using ActionDispatch::Integration::Session from the command-line

It may be useful to perform some requests to your controllers, from the Rails console. The following solution was tested against Rails 3.2.13, but I’m sure the tweaks should not be that big, to get it working with other versions:

session = ActionDispatch::Integration::Session.new(Rails.application)

after this, you can call get/post/put/etc on the session object:

session.get "/", {}, {}

The first hash represents the params to be sent to the request, and the second one, additional headers.

Most likely, your controller will require authentication. To ensure that we’re logged in, we go through the same steps as we would from a browser.

session.get "/login"
authenticity_token = session.response.body.match(/<[^<]+authenticity_token[^>]+value="([^"]+)"[^>]+>/)[1]
session.post("/login", {"user[email]" => "your@email","user[password]" => "your_password","authenticity_token" => authenticity_token})

So, we request login, and then we extract the authenticity token, and then we issue a post request to perform the login. Of course, in your case, the name of the parameters might be different, so please adapt accordingly.

Once we post to the sessions controller, we can then issue requests to controllers that need authentication.

Hope you found this useful!

Read More

using rake dsl outside of the Rakefile

Just include Rake::DSL in your class/file, and then you’ll be able to do the same things as in a Rakefile.

Read More

executable flag with git

git update-index --chmod=+x path/to/the/file
Read More

execute a command until success in bash

until somecmd; do echo "Retrying"; done
Read More

simulate a slow connection with toxiproxy

Toxiproxy.populate([
  {
    name: "toxiproxy_test_redis_tags",
    listen: "127.0.0.1:22222",
    upstream: "127.0.0.1:6379"
  }
])

r = Redis.new(port: 22222)

Toxiproxy["toxiproxy_test_redis_tags"].downstream(:latency, latency: 5000).apply do
  puts Time.now
  puts "Value is", r.get("ok")
  puts Time.now
end

Toxiproxy["toxiproxy_test_redis_tags"].upstream(:timeout, timeout: 2000).apply do
  # whatever
end

The example above would give you a “slow” redis. I received the following error on my system:

Unit toxiproxy.service failed to load

when trying to start toxiproxy via:

sudo service toxiproxy start

But, you can just start it manually. Do a updatedb and then a locate toxiproxy in case you don’t know where your binary is, and then you can populate it like in the example above.

Read More

triggering remote builds from jenkins

If you receive this error when triggering builds from your scripts:

Authentication required

<-- You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
->

Then install this plugin, and then call the following url:

curl http://JENKINS_URL/buildByToken/build?job=JOB_NAME&token=TOKEN_NAME
Read More

forward postgres from within vagrant to host

To be able to connect from outside to postgresql running in vagrant, make sure that postgresql.conf has this:

listen_addresses = ‘*’

And then restart the server.

Read More