having chrome extensions pulling data from ruby db - ruby

I would like to build a chrome extension (CE) that pulls data from a ruby db for a specific user. So, in a basic example, if an user submits their favorite color as 'red' and sport as 'tennis' into the db from the core website, when they click the CE, 'red' and 'tennis' will show up no matter where they are on the internet.
Any guidance on how to build something like this? Seems quite simple but am not sure how the CE files fit in with the ruby folder framework.
Also, is it possible to write to a ruby database from a popped out CE? i.e. - submitting 'red' and 'tennis' from the CE to the ruby database to go along with the previous example. Any guidance?
Cheers

This is a very general question so it sounds like you will need to learn a lot. Which can be a good thing :)
Here are the general steps you need:
Look into building an API for your ruby application. This will allow you to get data from your database. For example, you can
make an app where you go to http://yoursite.com/api/favorites and that will return a list of all favorites as JSON. Then in your Chrome Extension you can parse the JSON and display the results to the user. You will probably want to do this using an ajax call (see jquery.ajax for an easy way to use ajax).
Assuming you want user accounts, your user will need to be logged in. Then you can use your user's cookies to verify that they are logged in and show them custom info. i.e. going to http://yoursite.com/api/favorites will just show the favorites for that user, not for everyone.
Finally, submitting things to the database...you can have another route where users can send stuff. For example, if you go to http://yoursite.com/api/favorites/add?color=red then it will add the color red to that user's favorites. You will need to write all the logic for adding stuff to the database...again, it might help you to go through a rails tutorial and then look at building an API.
Related to #3, look into RESTful APIs. A good convention is that if you issue a GET request, you're asking for data, but if you issue a POST request, you are adding data (in your case, creating a new favorite).
Finally, for terminology: it's not a "ruby" database, it's just a database. You can access a database using almost any language, and it sounds like you are accessing it using ruby right now :)

If you only need to store data for one machine browsing anywhere online, chrome has a storage api that would work great.
If you do need a ruby server, I would recommend looking at sinatra.

Related

Firefox Extension - Database access

I want to make a Firefox extension that can store and retrieve data from a database. However I've only been finding solutions that would work locally for each user. I'd like every user to have access to the same database.
Is that possible?
It is possible to access remote SQL databases like MySQL and PostgreSQL with node.js modules, but it is more sensible to create REST API front ends to your databases and call them from the extension. Exposing the SQL calls directly in your web extension is not a good idea. It is basically bad security practice and will expose your database to hackers.
You will also need your addon to pass Mozilla's approval process if you are going to distribute publicly and I doubt the reviewers will be pleased to see raw SQL calls in your extension's code.
The more sensible way is to update the database is through a REST API front end.
A simple example on how to create a REST API for a Postgres database can be found at Node.js, Express.js, and PostgreSQL: CRUD REST API example - LogRocket Blog and this playlist show how to create a REST interface in a Firefox extension - Build a Firefox Extension from Scratch that integrates with Node.js - DEV Community
The above database example is quite simple. For real world use you will need a more advanced REST framework for your API which sanitizes the data before inserting it into the databasse. You have more reading to do here.
However if you need to make SQL calls directly from your extension which I still don't advise, you can include some packages from node.js in your web extension, and use browserify which extracts and packages the modules needed into your extension. Your addons though had better be for private or in-house use, not for public distribution.
Some nodejs modules for database access are - https://github.com/mysqljs/mysql, https://node-postgres.com/ and https://www.npmjs.com/package/pg.
Just a little advice. Feel free to ignore it if you have nothing to do with it. Your question sounds quiet generic. You should learn and doing it by yourself first and only ask here when there are specific issues you're stuck with.
By "locally", I think you mean via Web SQL or IndexedDB. They're called local database and their behaviors are totally different from what you're looking for.
I should haven't need to tell you to do this. Just in case. Of course first thing first you need to know how website is working for both front end and back end, not just local stuff, especially how they're communicating between each other. So you should know about HTTP request, Javascript, and AJAX.
What has it to do with Firefox extension?. Not just Firefox, browser extension is just another type of web page that overlaying the opened web page in all kind of browser. In Firefox the opened page is called activeTabs. The only difference from regular web page is you need to signup your account first, manifest.json file as your project root file, and it compile from command line with web-ext tools. In case if you're facing Cross-origin resource sharing (CORS) restriction, follow instructions HERE and allow the URL on server side.

Can a Dashboard widget use SQLite data?

I made an iOS app that has my favorite quotes in it by category. I wanted to turn this into a dashboard widget that notifies me of a quote of the day. I've never made a dashboard widget and only read the hello world example on apple site.
Can anyone suggest a good tutorial or help me understand the following:
What is the best way to take my SQLite database of quotes and make it available through a dashboard widget?
Thank you.
Dashboard is, like, really old... it has the look of a technology that's barely clinging to life support.
But if you want to fool around with it anyway, the way to access SQLite from a widget would be to implement a native widget plug-in that uses the SQLite library, exposing methods that your widget JavaScript code can call to fetch the info you need.
Or, as you seem to have done, repackage the data in a different form that you can access more conveniently from widget JavaScript.
I ended up using NerdTools and implemented an awk script to pull a random quote from a text file on my computer. So this was solved a different way.

Application to display information from database

I understand that this is a very broad question and could get flagged but I need inputs from experienced programmers and will ask it anyway. If there is another forum where I can post this question, please let me know.
Currently we manage all our application information in an Excel spreadsheet. At a high level it contains an app id, the server names that it is hosted on and the name of the environment. The Excel spreadsheet has become too large and I am looking to build a simple application for it.
Ideally, I would like to write this app on Windows as everyone uses Windows but dont know how to go about it in Windows. I then thought of using MySQL and PHP or Perl (CGI) to build this but thought of exploring something new. I read about Joomla and a few other CMS products which make it very easy to build websites but am not sure whether these allows me to pull information from a database.
I am seeking inputs on what would be a good way to way to build this application.
Use Joomla! CMS is a good choice and to pull data from database you may use webservice calls. So, you will able to create a CMS website using joomla and will able to pull data easily from database with the help of webservice.
You can get webservice support in joomla by installing component redCORE in joomla.
Component: https://github.com/redCOMPONENT-COM/redCORE
Wiki: http://redcomponent-com.github.io/redCORE/?chapters/webservices/overview.md
Other videos: https://www.youtube.com/watch?v=UzJkC7f9fJE
https://www.youtube.com/watch?v=1NRT5jh3Ewc
Joomla dev group discussion https://groups.google.com/d/msg/joomla-dev-cms/3OctbkIZlQw/5d_1MLrzbgYJ
You can also post questions in Joomla forum http://forum.joomla.org/
I think Joomla is a great option to handle big loads of information. If you already know PHP and don't need to reinvent the wheel, it's cool. The way of handling data in Joomla is using Components.
If you want to try, it would be as easy as installing a local copy of Joomla, building the field structure on component-creator.com installing it and importing the data inside the component using phpmyadmin.

Better user agent library for Codeigniter

I am looking for a more advanced user agent detection library for Codeigniter.
I want to add short tags for OS, Browser and Browser version to the body tag so
that I am able to write CSS that is gear towards different browsers and platforms.
Like this:
<body id="Win7 IE9">
Right now the default agent detection library for CI produces this:
<body id="Windows 7 Internet Explorer 9.22.2">
How can I "shorten" the response?
This is want I am looking to achieve: http://www.contao.org/en/blog/forget-about-browser-hacks-in-contao-210.html
Thankful for all input!
I don't think that user agent library is bad. It just do what it is supposed to do.
Maybe you should build a small helper or extend the user agent library, this is really simple task (you should look at agent->browser(), agent->version, agent->platfrom() etc.)
Despite what Contao says, these are browser hacks. Better way is to build your style sheets and/or javascript the right way (without this type of hacks). I don't ever needed different stylesheets (or browser specific classes) for different browsers.
I see what you are trying to do. To get away with this using CodeIgniter you'll have to basically rewrite the user agent library to return your shorter user agent strings (its time consuming but not too difficult)(the four user agent arrays are in: system/libraries/user_agents.php).
Its been more than a year since this question was asked but i am sure it will help someone in future. User agents names are defined in ./application/config/user_agents.php file in an associative array format you can change the value of array with the one you want.
Note: Changing the value in config file will reflect in the entire application. If you want to change in a particular area of application i would suggest to create your own function.
Try this
$this->session->userdata['user_agent'];

a script to log into webpage

I want to write a script to log in and interact with a web page, and a bit at a loss as to where to start. I can probably figure out the html parsing, but how do I handle the login part? I was planning on using bash, since that is what I know best, but am open to any other suggestions. I'm just looking for some reference materials or links to help me get started. I'm not really sure if the password is then stored in a cookie or whatnot, so how do I assess the situation as well?
Thanks,
Dan
Take a look a cURL, which is generally available in a Linux/Unix environment, and which lets you script a call to a web page, including POST parameters (say a username and password), and lets you manage the cookie store, so that a subsequent call (to get a different page within the site) can use the same cookie (so your login will persist across calls).
I did something like that at work some time ago, I had to login in a page and post the same data over and over...
Take a look at here. I used wget because I did not get it working with curl.
Search this site for screen scraping. It can get hairy since you will need to deal with cookies, javascript and hidden fields (viewstate!). Usually you will need to scrape the login page to get the hidden fields and then post to the login page. Have fun :D

Resources