can I make a ruby GUI in javascript/html/css? - javascript

this is not a ruby on rails question
I just finished up a ruby basics course on teamtreehouse and I'm sitting
here thinking of what I want to make to demonstrate to myself that I
grasped what I learned.
I have a plan to write a program to automate setting up new hire files
and folders on a network directory at my work at the click of a button.
It might be nice to have a GUI for it instead of running it through the
command line.
First off, is this possible to run ruby with javascript and html without
running it through a server?
I'm trying to think of different ways I would get ruby to speak with
javascript. My first thought was to use a JSON file to produce url links
from in my webpage, but I have no idea how I would run the ruby program
from the web page.
probably a dumb question. Im trying to come up with a good project to
get some confidence in bare bones ruby before I pursue ruby on rails or
sinatra.

One easy way to run Ruby and many other languages in the browser would be to use a Ruby to JS compiler like http://opalrb.org/. Here's a huge list of more languages then you can shake a stick at: https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js#ruby.
The only trick is to make sure that the compiler can also be run in the browser not just the code it produces.
Hopefully that helps.
---- edit ----
I think I perhaps didn't read your question as much as I should have. As for comunication between the server and the client goes, I would say go with sinatra. It's really very simple, and you don't even have to use a database if it's just a project to learn with. Just modify files and save your data that way.
If you want a more dynamic front end making AJAX calls then you can just make a route in sinatra that would return back the information in an easy to parse form for JS such as JSON.

Related

Any way to create an application with the local web page as an interface?

A few days ago I decided to make my own "interface" to make it easier to organize (and work with) some of my personal files. You know when a lot of related data, pictures and links are right in front of you and you can change them in a couple of clicks, this is very convenient.
I started by studying HTML, CSS and JS, because I thought that the changes made to the local page would be saved somewhere on my PC so I can just run Index.html and do whatever I want. But they didn't. Refreshing the page erased all changes.
Using browser localstorage does not suit me, because if I change the browser, the data will be lost. I wanted it to just open with Index.html and work fine even if I change my browser or move the site folder to another computer.
Then I decided to learn more about server-side languages (such as PHP or Node.js) because they are directly related to databases, so I was hoping to save changes through them. But these languages required me to really open the server, with ip and port tracking. And I just wanted to open a local page through one file, without any ports or connections via the console. So this method scared me off quickly.
So is there an easy way to make a local page like this? Maybe I have not studied well one of the above methods and it has this opportunity?
Or the best I can hope for is a simple application that will use that local page as an interface to interact with data? I accidentally heard about this possibility a long time ago. Then I will ask you to give at least a hint as to which language to choose for this.
I don't understand well everything that lies outside of vanilla HTML, CSS and JS, so a complete study of a complex language like Java or Python will be too difficult for me, and the goal is not worth such a lot of effort.
I hope I understand correcly what you are trying to do.
If your goal is to make an application to manage your files, I think the simplest solution will be, as you said, to look into NodeJS and the File system api which will let you interact with your files through javascript code.
Your program will have to be in two part that will have to interact:
the "front" html page
the "back" nodejs script
The downside is that you'll have to go deeper into your study of the language to learn how to create the interactions you want between your html file and your NodeJS application.
However, there is no need to open your server to the web to make it work. The NodeJS application can be set to listen to requests from only the computer that runs it (localhost).
I obviously can't get too much into details without knowing precisely what you want to do but you'll probably have to learn to make a local server with node (search "nodejs http" or "nodejs express"), then make requests to it via the html page's scripts (search "ajax request").
What you need to look into are (web based) content management systems. like strapi or "grand old dame" WordPress.

Wondering how to use Python within Node.js / Electron

I am working on an audio editing prototype. At the moment it is very simple, so it currently works as a Web App using JavaScript, HTML and CSS. This makes it possible to build as an Electron app, using Node.js to access the file system.
However, it makes heavy use of a Python program called Gentle, particularly the file align.py. I was wondering if it was possible to integrate this program somehow, given how frequently it is used.
I am not familiar with Python, but I have tried to work out if this can be done. I have read about child_process, python-shell and zerorpc. However, if possible, I do not want to force the user to install Python along with all the dependencies required for Gentle, as it is a difficult process with lots of room for error.
This is where I have become stuck. Ultimately I am looking for a way to use Gentle in a way which gives the appearance of it being part of the functionality as a single self-contained program, rather than butchered on with duct tape.
I realize Gentle includes the option for a REST API and a Python server, but I am more interested in using Gentle offline for faster functionality. I am also too broke to afford hosting.
I realize I am kind of working backwards, as the front-end normally comes after the back-end. If it is easier I can try to rewrite the code base in Python or a lower-level language, but I am trying to avoid this if possible.
Any help or suggestions would be greatly appreciated!
You can compile the Python program and include the resulting binary file into your Electron app and just run the binary via child_process. There are several ways to create executables from Python programs.

Bridging a Python back-end and JavaScript front-end

I'm currently working on a project that involves parsing through a user-supplied file, doing computations with that data, and visualizing the results using graphing utilities. Right now, I'm stuck with using Python as the back-end because it has scientific libraries unavailable in JavaScript, but I want to move the entire tool to a web server, where I can do much slicker visualizations using D3.js.
The workflow would be something like: obtain the file contents from the browser, execute the Python script with the contents, return jsonified objects of computed values, and plot those objects using D3. I already have the back-end and front-end working by themselves, but want to know: How can I go about bridging the two? From what I've gathered, I need to do something along the lines of launching a server, sending AJAX requests to the server, and retrieving data from the server. But with the number of frameworks out there (Flask, cgi, apache, websockets, etc.), I'm not really sure where to start. This will likely only be a very simple web app with just a file submit page and a data visualization page. Any help is appreciated!
Apache is a web server, flask is a web framework in python, websockets are a protocol, and cgi is something totally different, and none of them help you on the front end.
You could deploy a simple backend in flask or django or pylons or any other python web framework. I like django, but it may be a little heavy for your purpose, flask is a bit more lightweight. You deploy them to a server with a web server installed and use something like apache to distribute.
Then you need a front end and a way of delivering your front end. Flask / Django are both fully capable of doing so in conjunction with a web server, or you could use a static file server like Amazon S3.
On your front end, you need to load D3 and probably some kind of utility like jQuery to load and parse your data from the back end, then use D3 however you like to present it on screen.
Flask is easy to get up and running and is Python based. It works well with REST APIs and data sent by JSON (or JSON API).
This is one solution with which I have some experience and which seems to work well and is not hard to get up and running (and natural to work with Python). I can't tell you whether it is the best solution for your needs, but it should work.
If you are overwhelmed and don't know where to start, you can pick one of the options and google search for a tutorial. With a decent tutorial, you should have an example up and running by the end of the tutorial, and then you will know if you are comfortable working with it and have an idea whether it will meet your needs.
Then you could do a proof-of-concept; make a small app that just handles one small part (the one you are most concerned about handling, perhaps) and write something which will do it.
By then, you can be pretty sure you have a good tool for the purpose (unless you were convinced otherwise by the proof-of-concept -- in which case, try again with another option :-))

Ruby on Rails and Javascript - Guideline help

I am a beginner in Ruby on Rails and I want to develop an app with many bells and whistles using Javascript (and jQuery UI).
The bells and whistles like drag and drop, instantly highlighting things when things are selected and movable portlets are important. This can lead me to creating most of the site in Javascript, which I have read is not the best thing.
My question is, what guide do I use so that I know when to use Server-side code (RoR) and when to use Javascript (other than for things that can't be helped).
I could make sure that Javascript is always enabled (or the app won't work), but is that a good idea?
Any help would be greatly appreciated.
The asset pipeline guide will teach you how to include your static assets in your code. As far as when to use javascript vs server side code, you should also look at these posts on unobtrusive javascript.
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-technique/
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
If you follow that paradigm you'll find a good separation between what's done in the server and what's done on the client, where all of the data is generated server side and javascript is used for interactivity.
I recommend you to start with reading asset pipeline guide

updating countdown timers

I'm starting to build a script for a Penny Auction site like swoopo.com
What framework should I use?
Whats the best way to keep the timers updated without using too much bandwidth?
This all started when I started looking at all the junk thats currently out there.
Most are using PHP and javascript and I feel there is a much better solution.
I have only ever coded in PHP and java and am looking to use this project to learn something new. I have been looking into RoR, would this be suitable for this kind of project?
You must be able to do server pushes.
In ruby you can use orbited (http://github.com/collin/orbited-ruby).
You can do all webapplication you want in all kind of programmation language.
Ruby on Rails is made to do webapplication. You want made a webapplication. So you can do it with this framework. There are nothing better to say.
Made an application with any language can be slowest than an other even if the language is quicker. It's always depends how you code it.
Ruby On Rails help to maintain easily your code and more readable. It's maybe not the better language in each case. But in each case, it's works and do what you want.

Categories