Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

EAT THE EGGS RICOLA posted:

I just switched from a Windows machine doing dev stuff in a Linux VM to a Mac. Anything I should know or keep in mind about doing dev stuff on one? I've never used a Mac before other than just casually.

homebrew is a pretty nice thing, but you'll probably end up compiling more things from source than you're used to. I recommend not trying to outsmart homebrew with the permissions it wants (at one point it was asking you to chmod /usr/local). It sounds kind of awful, but dealing with the alternative is much worse.

good jovi fucked around with this message at 02:03 on Sep 5, 2013

Adbot
ADBOT LOVES YOU

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

kayakyakr posted:

Agree with all of the above. I think I'm going to start on a new side project today and try to test everything along the way. make new habits.

I've liked rspec, but have never been comfortable with testing controllers... to mock or not to mock, that is the question.

Testing controllers has always been the least fun part for me. I usually just do enough to be satisfied it's not horribly broken. If you need much more than that, your controller is probably too fat anyways.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Lexicon posted:

I feel like I should know the answer to this, but apparently don't: is it possible to rely exclusively on 'bundler' for gem installation? I'm about to start using middleman for static site generation, and all the tutorials are requiring that I 'gem install middleman' first, despite referencing bundler later. Can I not just structure things so only bundler installs the gem? Or is that not feasible because the 'middleman' command needs to be available in the terminal?

Yes, you can just let bundler handle all the gem installation. The only downside is that you might have to preface your middleman calls with "bundle exec".

Bundler doesn't strictly sandbox gems like using gemsets, or python's virtualenv. Think of it as a filter on the larger pool of gems that you have installed, making sure that only the ones you've specified are activated.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Sil posted:

Wait. Where did I pick up that """ """ thing? It must have been some rails tutorial book, but I could have sworn they said that's the way to do multiline strings in ruby. I see now, in IRB, that regular string literals do that just fine.

Have you been reading any python tutorials? It uses triple quotes for multiline strings.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Pardot posted:

In fact, the check first really doesn't do anything because someone could have added a violating record in between the check and the insert. Which is why the rails unique validator is huge bullshit that doesn't do anything.

Don't you see, uniqueness checks are "business logic" and don't belong in the database.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Pollyanna posted:

Right, I think I get it...but then the Rails tutorial goes through setting up authentication and factories and stuff from scratch. Am I basically gonna be replicating the Rails tutorial every time I want to set up something with authentication and a database?

Only in the sense that yes, you're going to have to actually write your application. Eventually you figure out what gems best handle common tasks (like authentication) for you, and maybe even write a few of your own to encapsulate anything you find yourself writing over and over again.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

On that topic, it looks like Rails is finally getting builtin support for foreign keys! http://weblog.rubyonrails.org/2014/8/20/Rails-4-2-beta1/

(Until that lands, everyone should probably be using foreigner)

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

This isn't strictly an answer to your question, but I'd do something like this:

code:

class Door < ActiveRecord::Base
   has_many :leases
   has_one :active_lease, ->{ merge Lease.active }, class_name: 'Lease'
 end

 class Lease < ActiveRecord::Base
   belongs_to :door
   scope :active, ->{ where("? between start and end", Time.now) }
 end

It's the responsibility of a lease to define what "active" means. And defining active_lease as a relation rather than a method lets you avoid the N+1 problem by includesing :active_lease in your initial Lease query and not fetch it for every individual lease.

i.e.
code:

Door.all.includes(:active_lease).each do |d|
  puts d.active_lease
end

would only have to make 2 queries.

good jovi fucked around with this message at 00:05 on Sep 1, 2014

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

I had a interviewer ding my code sample for no tests because he didn't look in spec/.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Also, don't create database objects in before(:all) blocks. They are executed outside of the transaction, so those rows won't get cleaned up.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

prom candy posted:

I think it would be interesting to open an app folder and see something like

code:
app
 posts
   - model.rb
   - decorator.rb
   - controller.rb
   views
     - index.html.haml
     - show.html.haml
It brings up some interesting questions though, like what if you had separate controllers and views for an admin section that operated on posts vs. the public user experience? What if you wanted to add API controllers and views? The plus side obviously is that when you open your app folder you can immediately see what your app is all about, I think Robert Martin has argued for something like this in Rails apps.

We have a rather large Angular app at work that we organize this way, and I think it has worked out rather nicely. There are half a dozen or so people working on the app, and organizing by feature helps at least contain people's unique ideas about where code belongs or what it should be called.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

duck hunt posted:

I've been a Python developer for a long while, and I'm inheriting and taking on a lot of Ruby projects at work right now. We use Puppet extensively as well as other internal tools written in Ruby. Seems like there is a lot of overlap conceptually between Python and Ruby. Python meet ups have stupid names about snakes and Holy Grail this and that, while all the Ruby meet ups seem to happen on Tuesdays.

Can you guys recommend a book (I need to have pages) to help pick up Ruby? Otherwise I was just going to default to Oreilly.

Especially for someone coming from Python, I recommend Metaprogramming Ruby 2. It may sound kind of specific, but I'm assuming you don't need to know how if statements work or whatever. The metaprogramming bits are most of what distinguishes Ruby from Python anyway.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Docjowles posted:

I'm having my first real encounter with ruby and I have what is probably a really retarded question. Why does this ERB template not do what I expect? It's being run through Chef, if that matters:

What if you replace the whole thing with
code:
export APPDEFINE="<%= @config.fetch(:override_app_define, "default") %>"
What you have looks like it should work, but I've never used Chef, so there might be some specific weirdness related to that. Is @config actually just a Hash?

This is really a Rails thread, but there doesn't appear to be a general Ruby thread, or a Chef thread, so whatever.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

These days you should really just be checking in a database.yml and managing any secrets or environment-specific config through environment variables (ie DATABASE_URL).

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

duck monster posted:

I'm fairly new to rails (Coming from a django background, new jobs uses rails), but was completely dumbstruck that active record doesnt create database constrains on relationships, and the dude who wrote them apparently doesnt believe in them. Thats a pretty bad sign in my books, so whats the alternatives?

AR will create foreign key constraints if you tell it to - http://guides.rubyonrails.org/active_record_migrations.html#foreign-keys

The only other ORM I've seen any kind of support for in the Rails world is Mongoid, and gently caress that noise.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Pollyanna posted:

but from what I can tell, this fails in @asset.update(asset_params) due to the arbitrary tag not having an ID, and not existing yet. What's the general approach for something like this, where you both update and create a resource at the same time?

edit: I suspect this has something to do with accepts_nested_attributes_for.

Are you on postgres? Just store the tags in an array field on Asset. You've gotta set up an index on the tags, but it's so much easier to deal with.

EDIT: Or I could actually read your problem. An array would actually be really bad for you, there isn't really an efficient way to get all the tags.

good jovi fucked around with this message at 20:17 on Jun 8, 2016

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Am I correct that using native postgres types forces you to switch your app schema over to :sql format? That seemed to be required last time I tried to use them, and I can't remember why that was undesirable exactly. Has anyone experienced any problems there?

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Handling multiple ruby versions is a breeze. rbenv has an extension called "ruby-build" (also available through Homebrew). Just install that and drop a .ruby-version file in each project. No problem*

Peristalsis posted:

On a completely different note, I have a side project coming up that involves writing a custom scheduling app. It's for a research lab that needs to send text messages to their subjects on a pre-determined schedule, and send occasional ad hoc texts on demand.

The lab has an account with TextMark, which I can use to send the texts via cURL commands to some URL somewhere. My question is about the overall structure of the program. Is this the kind of thing that the rufus scheduler does well, or should I just have a main loop somewhere that checks every 30 seconds if it's time to send the next text(s).

It also seemed like a not-too-bad use case for a second thread. The main thread would just be the normal app, which allows users to manage subject lists, text schedules, etc. The second thread would be the scheduled texting thread, which sends a text and then sleeps until the next text is due. That's probably overkill, but I'd enjoy tinkering with multi-threading, I think, as long as I'm not just inviting a world of pain and despair by dabbling in thread stuff. (As I understand it, the Global Interpreter Lock means there isn't ever genuinely concurrent execution of multiple threads, but rather it enforces a sort of time-slicing between the threads at the Ruby level. I don't anticipate this being a demanding app, and I think time-slicing would be just fine in performance terms.)

To address your actual question, the first approach that comes to mind is to have a cron job running that is responsible for the actual sending of messages. So the rails app is just responsible for dumping scheduled messages into the database. Decide on a minimum resolution for message scheduling (say, 10 minutes), and then have the cron job run on that schedule (say, every 10 minutes). The job will then look in the database for any messages scheduled to go out in the past that haven't been sent yet and send them.

That's just one approach, though, and assumes a certain scale (relatively small). Other options might depend on the infrastructure available to you. If you wanted to use a message queue like RabbitMQ or SQS, they both have a concept of delayed messages. Instead of putting SMSs in the database, you could just throw them on the queue with a delay of (send_time - current_time) and then again have a separate process responsible for consuming messages off that queue and just sending them out right away.

In general, something like this wouldn't be done with threading inside the web app process, but by a separate process (cron job, sidekiq worker, whatever) solely responsible for handling that out-of-band work. The web process should be dedicated to serving up web pages, and anything not essential to the rending of those pages should be shipped off.

*it's ruby, so "no problem" means "no problem as long as your use case exactly matches that of the program's author"

Adbot
ADBOT LOVES YOU

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Partycat posted:

I have been working on developing my internal toolset in ruby and rails, and have been slowly improving with my techniques, built my own internal gem for some modules, etc

Is the general opinion on this that I should be doing this in python instead at this point? Is Ruby falling apart into decay?

Python immediately turned me off by being column/space dependent giving me COBOL flashbacks, was really hoping not to have to deal with that poo poo or line terminators ever again.

No, it’s fine.

Ruby’s not going anywhere. They just previewed some upcoming features in Ruby 3 that sound quite neat, too.

If you want to do a different language, try something with a very different paradigm. Expand your mind a bit. Like, say, clojure, or perhaps an Elm frontend for your rails app. Vastly different languages like that actually complement each other better in your brain, in my experience. Seeing other ways of doing things is going to make you a better programmer. Going from Ruby to Python is just going to make you focus on piddly poo poo like indentation.

The fact that you’re even asking the question suggests that you’re not going to be applying for any jobs where they’d expect you to have really deep, specialized knowledge about a particular language. So get some breadth.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply