A few months back I did a pairing session Chris Hunt and together we built a Node Chat app using the very convenient Getting Started Guide on Socket.io's doc page. We successfully completed the guide and deployed the app with minor hiccups.
Once a month here at work, we take part in a "hack day" where we can work on any project that is vaguely relevant to the business we are in or the company we work for. I took on the challenge to creating a new chat app and possibly implementing as a special feature at work.
One thing I noticed right after completing the app was the lack of user names displayed inline. While chatting with Chris on our app, it was easy to know which messages were not mine, but it would have been nice to know in case I needed to review the history.
Knowing the little node I knew I starting looking into the redis and socket.io-redis npm's and figure thats what I needed to save the username when prompted, but after a bit of time scaling the api and documentation it turned out it was only needed to save the printed chat messages for the session.
I was dissappointed when I did not find a blog post on the subject, but eventually found an old youtube video explaining exactly what I needed to know.
Each user can login with a session or socket and within each socket I needed to save their username. I was actually saving the username to late in the game and every message had the same user's name. I had to access the socket and save the username the same time as the message. Here is an example of the code:
*notice how I am prepending the chat name in the chat message while emitting the socket.
Here is the jQuery providing the chat in my view:
I create a new socket call to save my username that was collect from a javascript prompt and voila, the user's username got displayed each time they printed a message. I am pretty proud that I was able to complete and publish the chat app to heroku in time to present in our hack day presentation meeting.
*I made the dangerous decision of publicly displaying a chat to a projector screen.
As far as redis, I only need that to save the previous chat messages, which for the purpose of my feature, it is not needed. There is still work to be done on the front end and how it will be render to make it a new feature, but I am pretty proud of this little guy - My Chat App.
This is my personal blog and journey in learning a new skill, Web Developing. In only 7 months I made a career change into this field by dedicating 25(avg) hours a week in studying Ruby. #All words are my own, except the ones I copy and pasted.
Showing posts with label node. Show all posts
Showing posts with label node. Show all posts
Saturday, January 31, 2015
Tuesday, January 13, 2015
Chron job in node
After my recent node battle, I knew the war was not over. I still needed to set up my node script to run in the background. I know with Javascript be an event based I should be able to create a chron job for checking when ever a new signup on the form happens, I should be able to send an invite.
I first started with the forever npm package but similarly with my original requirements for running the unstable version of node, I was unable to use that package, as it is not updated for that.
I then found a StackOverflow question on running the code in an interval. As I thought, this was pretty easy. I am impressed or frustrated with node at the same time, mainly because its not Ruby. In the same vain is not too bad and I can see myself using more in the future for small scripts as the community includes some of the smartest programmers out there and can only increase my experience knowing yet another server side language.
My Code:
I first started with the forever npm package but similarly with my original requirements for running the unstable version of node, I was unable to use that package, as it is not updated for that.
I then found a StackOverflow question on running the code in an interval. As I thought, this was pretty easy. I am impressed or frustrated with node at the same time, mainly because its not Ruby. In the same vain is not too bad and I can see myself using more in the future for small scripts as the community includes some of the smartest programmers out there and can only increase my experience knowing yet another server side language.
My Code:
Monday, January 12, 2015
node Battle: The integration of slack and typeform
This weekend was planned for the exploration of new territory. I have had a new idea for my first Ember app for quite some time and was ready begin from `ember new`.
I also recently joined up with a group to startup a new idea (more details in a future post) for a community. My first task for the group was to integrate slack into the app, sounds easy enough since there is a popular blog post on how someone did it in php. I am not exaggerating when I say I have had no php experience, but expected to learn it quickly enough to follow a blog post, well the blog post was not as clear as I would of thought it to be. I expected more steps and ideas on how to run a php script and the s/o questions and google searches made too many assumptions on my skill level in php.
After spending about an hour in php, I decided to search for a different solution and possible come back to php if needed.
Here comes the node
Now what I was doing is farely new and the blog post was only written 2 months ago, either there is not a need for this sort of slack integration or I am on the cutting edge. Regardless, when I tried searching only 3 implementations came up, and one was just a bot reposting the first php article.
Luckily the other choice was node, a version of Javascript I had some experience learning in. I stumble on the cleverly named slack-typeform-inviter, great for seo, and quickly enough of the code to realize it made sense. I forked the project and began inserting the needed API keys for Slack and Typeform.
I then Ran the code and boomed error, `SyntaxError: Unexpected token *`. Hmmm, why would someone post code with syntax errors?
Actually it is not a syntax error, but actually a new syntax for the release candidate .11. Yep the code was written on an unstable version of node and I was an unstable developer at that point.
Now I wrote my solution in what took about 5 seconds for you to read, but it took about 3 hours of banging my head on the keyboard trying to figure out how to debug this code. I removed the "*'s" from the deferred calls, which I found out to be to sort of like yields for arguments, but once those were removed I was getting errors on the yields.
I finally removed the yields and got the code fail everywhere there was a "request" or "response" call. This was weird, so I ended up emailing the contributor. In hindsight I recommend opening up an issue on github instead, I got a super quick response letting me know it was the newest unstable node code and a picture of the developer at a KPOP concert in Thailand. I felt bad to bother him but relieved that I could get the code to work.
But only if it was that easy, I did spend about 4 hours figuring out how to install an unstable version of node and debug why it was not working on my computer. Those fours plus probably more as I moved into the next day were spend installing dev tools on my wife's mac to test that the code worked. Luckily all I had to do was copy and paste my .vimrc, which is testament to VIM and why you should use it.
I ended up discovering nvm (similar to rvm) to install the "unstable" version of node and switch back and forth when needed.
There was an incredible amount of troubleshooting this weekend, but it taught a deep understanding of how npm and node_module management works. It also gave a chance to write some production ready node code. Also the code works which is a relief.
Thanks to Chad Scira for being so responsive in email and originally writing the slack-typeform-inviter
*I have submitted a pull request to help anyone else who might want to use the node pack in the future. Which has already been merged!
Now I hope next weekend I can get past ember new.
I also recently joined up with a group to startup a new idea (more details in a future post) for a community. My first task for the group was to integrate slack into the app, sounds easy enough since there is a popular blog post on how someone did it in php. I am not exaggerating when I say I have had no php experience, but expected to learn it quickly enough to follow a blog post, well the blog post was not as clear as I would of thought it to be. I expected more steps and ideas on how to run a php script and the s/o questions and google searches made too many assumptions on my skill level in php.
After spending about an hour in php, I decided to search for a different solution and possible come back to php if needed.
Here comes the node
Now what I was doing is farely new and the blog post was only written 2 months ago, either there is not a need for this sort of slack integration or I am on the cutting edge. Regardless, when I tried searching only 3 implementations came up, and one was just a bot reposting the first php article.
Luckily the other choice was node, a version of Javascript I had some experience learning in. I stumble on the cleverly named slack-typeform-inviter, great for seo, and quickly enough of the code to realize it made sense. I forked the project and began inserting the needed API keys for Slack and Typeform.
I then Ran the code and boomed error, `SyntaxError: Unexpected token *`. Hmmm, why would someone post code with syntax errors?
Actually it is not a syntax error, but actually a new syntax for the release candidate .11. Yep the code was written on an unstable version of node and I was an unstable developer at that point.
Now I wrote my solution in what took about 5 seconds for you to read, but it took about 3 hours of banging my head on the keyboard trying to figure out how to debug this code. I removed the "*'s" from the deferred calls, which I found out to be to sort of like yields for arguments, but once those were removed I was getting errors on the yields.
I finally removed the yields and got the code fail everywhere there was a "request" or "response" call. This was weird, so I ended up emailing the contributor. In hindsight I recommend opening up an issue on github instead, I got a super quick response letting me know it was the newest unstable node code and a picture of the developer at a KPOP concert in Thailand. I felt bad to bother him but relieved that I could get the code to work.
But only if it was that easy, I did spend about 4 hours figuring out how to install an unstable version of node and debug why it was not working on my computer. Those fours plus probably more as I moved into the next day were spend installing dev tools on my wife's mac to test that the code worked. Luckily all I had to do was copy and paste my .vimrc, which is testament to VIM and why you should use it.
I ended up discovering nvm (similar to rvm) to install the "unstable" version of node and switch back and forth when needed.
There was an incredible amount of troubleshooting this weekend, but it taught a deep understanding of how npm and node_module management works. It also gave a chance to write some production ready node code. Also the code works which is a relief.
Thanks to Chad Scira for being so responsive in email and originally writing the slack-typeform-inviter
*I have submitted a pull request to help anyone else who might want to use the node pack in the future. Which has already been merged!
Now I hope next weekend I can get past ember new.
Friday, December 5, 2014
Pairing in node with a Healthy Hacker
I had the opportunity yesterday afternoon to pair with Chris Hunt, host of the new podcast Healthy Hacker. After listening to the "Growing as a Programmer" he made an interesting announcement that I have not yet heard anyone else do at his caliber of programming. He was offering free time to pair with him in 30min increments. I signed up rathe quickly after noticing a number of open spots.
At the time of signing up you have to put in a subject to pair on for the session; With me being really ambitious I chose a subject I had zero experience in, node.js's socket_io plugin. I planned on messing around with it prior, in hopes to add live chat to my Ruby Newbies page, but it didn't happen. I got extremely side tracked with learning Ember and updating my Chuych app.
My overall impression of pairing with an absolute stranger on a subject I had no knowledge on, was great. Not only did we finish the socket_io tutorial, we also got it pushed to heroku and tested it out live. I did the driving in the pairing, while Chris navigated through the documentation, which was extremely valuable in me learning. We did get hung up on pushing a node/express.js project to heroku, since both our experience were in Rails, but he was able to pin point in the docs how to update the server to the heroku environment variable.
I am actually pretty stoked to continue to work on this project on my own and implement it with the RubyNewbies things. Node is a new frontier for me and I hope to continue exploring the various plugins and frameworks associated with it. To view our code check it out here.
If you are interested in pairing with Chris, checkout his calendar and sign up soon, but there seem to be very limited spots available.
At the time of signing up you have to put in a subject to pair on for the session; With me being really ambitious I chose a subject I had zero experience in, node.js's socket_io plugin. I planned on messing around with it prior, in hopes to add live chat to my Ruby Newbies page, but it didn't happen. I got extremely side tracked with learning Ember and updating my Chuych app.
My overall impression of pairing with an absolute stranger on a subject I had no knowledge on, was great. Not only did we finish the socket_io tutorial, we also got it pushed to heroku and tested it out live. I did the driving in the pairing, while Chris navigated through the documentation, which was extremely valuable in me learning. We did get hung up on pushing a node/express.js project to heroku, since both our experience were in Rails, but he was able to pin point in the docs how to update the server to the heroku environment variable.
I am actually pretty stoked to continue to work on this project on my own and implement it with the RubyNewbies things. Node is a new frontier for me and I hope to continue exploring the various plugins and frameworks associated with it. To view our code check it out here.
If you are interested in pairing with Chris, checkout his calendar and sign up soon, but there seem to be very limited spots available.
Sunday, November 30, 2014
ember CLI install and murdering my node
Never ever ever sudo with npm installs. I did not know this and probably unknowingly did this all the time. In my early days in Rails I never had an issue, only because once you install Rails it's stalled and be upgraded in the Gemfile. With Javascript, I am quickly finding that a lot of things require the node package manager (npm) to install and upgrade. I recently upgraded my ember to use the ember-cli, came across this sudo errors, but thanks to this homebrew issue thread I was eventually able to solve my problem.
My solution included this premade bash script called "murdering your node." From there I could clean install node and ember-cli.
If you are interested in learning Ember I suggest starting with the ember-cli-101 book. It is hands down the best Ember tutorial I have done and has gotten me pass some of the toughest hurdles I have faced in learning a Javascript MVC framework on my own.
*FYI: just to be clear you can sudo your way through npm, but it is not recommended, especially with ember-cli.
My solution included this premade bash script called "murdering your node." From there I could clean install node and ember-cli.
If you are interested in learning Ember I suggest starting with the ember-cli-101 book. It is hands down the best Ember tutorial I have done and has gotten me pass some of the toughest hurdles I have faced in learning a Javascript MVC framework on my own.
*FYI: just to be clear you can sudo your way through npm, but it is not recommended, especially with ember-cli.
Subscribe to:
Posts (Atom)





