Is there a tutorial on how to use AREL or Reference document? - arel

I am looking :
for a reference document that lists what methods are available?
a tutorial on how to setup and execute a query, then build up complex queries?
Checked README, questions that are tagged as Arel here but most are about how to setup where clauses, complex queries not how to use it in the first place ...
Thanks all in advance

Generated docs are your best bet if you're looking for an official reference.
As for tutorial, these cool slides helped me learn arel (props to Philip C).

Related

Is this a job for Yeoman?

I use Yeoman, and I dig it.
However recently I have been wanting more complex code generation tools - now I know I can build custom generators, but I am wondering if people think this is the role/job/whatever that Yeoman is built to play.
Examples are,
Generating a base REST API (in Node) from a JSON schema
Generating MySQL DB Schema from JSON schema etc.
Although I could bend Yeoman to do this - do people think this is a realistic direction?
Is there a better tool for the job?
(Currently I have a bunch of custom Node scripts that suffice).
My humble opinion:
Yeoman is first and foremost a front end tool to create webapps.
Your task seems to be backend related.
You can still use grunt to scaffold your project though.
http://gruntjs.com/project-scaffolding
Cheers

making query using asyncdynamo

I am using asyncdynamo library to interact with Amazon Dynamo DB. I can successfully get items using get_item() but don't know how to format a query for it. I have tried different patterns but got no luck. The Library itself doesn't have any documentation to provide the information on this.
If someone else has used and made queries using asyncdynamo then please help.
The lack of documentation for Asyncdynamo really kills the usefulness of the project. You might consider using Dynochemy instead, since at least it has some examples:
https://github.com/rhettg/Dynochemy

Upshot helper extension using Linq To Sql

This is my first question on SO, so please bear with any mistakes/irregularities.
I wanted to implement SPA for my new project, Hence I reached Steve Sandersion's after some googling blog.
Looking at the code hosted on github, I noticed that I had to use EF to use Upshot, but my DAL is already written in Linq to Sql, which will be very tiresome to migrate to EF.
So my questions are as below
Has anyone successfully used upshot with L2S? If yes some example would help.
Is there any other way to implement the SPA without upshot so that I can reuse my DAL in L2S?
Edited
I just found today that this question stands useless, as using upshot will not be feasible. Microsoft has stopped working on Upshot.Some one please close this question.
I don't think it is possible. Microsoft has made it sure that people using Linq-to-sql don't survive.
Better use something like jquery and web api with some js mvvm libraries.
As far as I know this should be possible. When using upshot you don't need to use entity framework, you can do the wireing for your self.
In my ria 4 html demo, I make use of ria services to get the data from the server to the upshot client. This way it doesn't depend on the DAL you have. Ria services works by conventions, meaning insert, update and remove methods are present on every domaincontext and you can implement them as you want. For more info you can read this blogpost on setting everything up. And this on for the CRUD operations.

Where to put a custom function in CakePHP

I have a function in one of my views that formats data coming from the DB before displaying it. Since I use this function in many views, I'd like to make a global function that would be accessible from every view. How would I do that ?
As mentioned in the other answers, creating a helper is probably what you are looking for. See the cookbook entry for more information.
To make your helper available in all your views, add the helper to the $helpers array of your AppController (app/Controller/AppController.php).
Creating a helper (as Headshota and preinheimer explained) is the best idea if the function is complex..
But if your function is simple,
you can open the file app/config/bootstrap.php
write your function in this file and that's it..
the function will be accessible anywhere (models, controllers, views, etc)
hope that helps...
I think you want to create a view helper, here's an example one: Minify Helper
Yes you have to create your owns View Helpers.
You will find the documentation in the Section "View > Helpers" of the cook book : here
But the section "Core Libraries > Helpers" just explains how to use the ready-to-use cakephp Helpers like HtmlHelper or FormHelper: here
Likewise you can note that this is the same logic with firstly controllers and components, and secondly model and behaviours.
Then the cook book presents the core components in core-libraries/toc-components
How to create your own is explained in controllers/components
The core behaviours are presented in core-libraries/toc-behaviors
The how to create your own is in models/behaviours
This system is really efficient and makes cakePHP a handy framework (thank you the great documentation) that implement efficiently the Model-View-Controller design pattern.
If you understand that question correctly, you never ask yourself this kind of issue about cakePHP and by the same time, about the MVC pattern.

Studying standard library sources

How does one study open-source libraries code, particularly standard libraries?
The code base is often vast and hard to navigate. How to find some function or class definition?
Do I search through downloaded source files?
Do I need cvs/svn for that?
Maybe web-search?
Should I just know the structure of the standard library?
Is there any reference on it?
Or do some IDEs have such features? Or some other tools?
How to do it effectively without one?
What are the best practices of doing this in any open-source libraries?
Is there any convention of how are sources manipulated on Linux/Unix systems?
What are the differences for specific programming languages?
Broad presentation of the subject is highly encouraged.
I mark this 'community wiki' so everyone can rephrase and expand my awkward formulations!
Update: Probably didn't express the problem clear enough. What I want to, is to view just the source code of some specific library class or function. And the problem is mostly about work organization and usability - how do I navigate in the huge pile of sources to find the thing, maybe there are specific tools or approaches? It feels like there should've long existed some solution(s) for that.
One thing to note is that standard libraries are sometimes (often?) optimized more than is good for most production code.
Because they are widely used, they have to perform well over a wide variety of conditions, and may be full of clever tricks and special logic for corner cases.
Maybe they are not the best thing to study as a beginner.
Just a thought.
Well, I think that it's insane to just site down and read a library's code. My approach is to search whenever I come across the need to implement something by myself and then study the way that it's implemented in those libraries.
And there's also allot of projects/libraries with excellent documentation, which I find more important to read than the code. In Unix based systems you often find valuable information in the man pages.
Wow, that's a big question.
The short answer: it depends.
The long answer:
Some libraries provide documentation while others don't. Standard libraries are usually pretty well documented, whether your chosen implementation of the library includes documentation or not. For instance you may have found an implementation of the c standard library without documentation but the c standard has been around long enough that there are hundreds of good reference books available. Documentation with hyperlinks is a very useful way to learn a new API. In any case the first place I would look is the library's main website
For less well known libraries lacking documentation I find two different approaches very helpful.
First is a doc generator. Nearly every language I know of has one. It basically parses an source tree and creates documentation (usually as html or xml) which can be used to learn a library. Some use specially formatted comments in the code to create more complete documentation. JavaDoc is one good example of this. Doc generators for many other languages borrow from JavaDoc.
Second an IDE with a class browser. These act as a sort of on the fly documentation. Some display just the library's interface. Other's include description comments from the library's source.
Both of these will require access to the libraries source (which will come in handy if you intend actually use a library).
Many of these tools and techniques work equally well for closed/proprietary libraries.
The standard Java libraries' source code is available. For a beginning Java programmer these can be a great read. Especially the Collections framework is a good place to start. Take for instance the implementation of ArrayList and learn how you can implement a resizeable array in Java. Most of the source has even useful comments.
The best parts to read are probably whose purpose you can understand immediately. Start with the easy pieces and try to follow all the steps that are hidden behind that single call you make from your own code.
Something I do from time to time :
apt-get source foo
Then new C++ project (or whatever) in Eclipse and import.
=> Wow ! Browsable ! (use F3)