<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Programming Logic</title>
	<atom:link href="http://www.programminglogic.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.programminglogic.com</link>
	<description>Algorithms, Computer Science and Programming Puzzles</description>
	<lastBuildDate>Mon, 09 Oct 2017 17:42:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Running Heroku Apps Locally on Port 80, with Facebook Connect</title>
		<link>https://www.programminglogic.com/running-heroku-apps-locally-on-port-80-with-facebook-connect/</link>
					<comments>https://www.programminglogic.com/running-heroku-apps-locally-on-port-80-with-facebook-connect/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Mon, 09 Oct 2017 17:42:49 +0000</pubDate>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=730</guid>

					<description><![CDATA[Suppose you are hosting your app on Heroku or some similar provider, and you rely on Facebook Connect for user authentication. How do you run your app locally so that you can develop and test without messing with the live version? Using a third party API like Facebook Connect makes it tricky because you need [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Suppose you are hosting your app on Heroku or some similar provider, and you rely on Facebook Connect for user authentication. How do you run your app locally so that you can develop and test without messing with the live version?</p>
<p>Using a third party API like Facebook Connect makes it tricky because you need to specify a URL on your Facebook app, and it either needs to be localhost or your live domain, like app.herokuapp.com. </p>
<p>The solution:</p>
<p>1. sudo vim /etc/hosts and add a line like this</p>
<p><code>127.0.0.1&nbsp;&nbsp;&nbsp;&nbsp;app.herokuapp.com</code></p>
<p>2. Your node/heroku app runs on port 3000, but the IP configured above will only work for port 80, the default for http. We need to redirect all 80 traffic to port 3000, with the command below.</p>
<p><code>sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000</code></p>
<p>Notice that the above command works for local requests. If you have external traffic on the server, you need to run this other command:</p>
<p><code>sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000</code></p>
<p>That is it. Remember to use HTTP and not HTTPS locally as well, else you will get a browser warnings or an error.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/running-heroku-apps-locally-on-port-80-with-facebook-connect/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mongodb and Node.js Timezone Problems with Date Objects</title>
		<link>https://www.programminglogic.com/mongodb-and-node-js-timezone-problems-with-date-objects/</link>
					<comments>https://www.programminglogic.com/mongodb-and-node-js-timezone-problems-with-date-objects/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Mon, 09 Oct 2017 17:33:03 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=728</guid>

					<description><![CDATA[When you start working with Node/Mongodb you probably will resort to the native Date object to play around with and store dates. I did it too, only to discover that you will face a lot of timezone related problems if you do that. Mongodb stores dates on the UTC timezone as default, but your Node [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When you start working with Node/Mongodb you probably will resort to the native Date object to play around with and store dates. I did it too, only to discover that you will face a lot of timezone related problems if you do that.</p>
<p>Mongodb stores dates on the UTC timezone as default, but your Node app will create Date objects using your local timezone. </p>
<p>Most apps don&#8217;t need date granularity at hour level, only day, so dealing with timezone issues is crazy. </p>
<p>A better approach? Store your dates as a string using the &#8216;YYYY-MM-DD&#8217; format. It will be much simpler, and you will still be able to query your DB filtering by date, since string comparison will work perfectly.</p>
<p><pre><code>Sales.find({id:id,date:{&quot;$gte&quot;:startDate,&quot;$lt&quot;:endDate}},function(err, purchases){

});</code></pre></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/mongodb-and-node-js-timezone-problems-with-date-objects/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>List of Basic FFmpeg Commands</title>
		<link>https://www.programminglogic.com/list-of-basic-ffmpeg-commands/</link>
					<comments>https://www.programminglogic.com/list-of-basic-ffmpeg-commands/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Sun, 10 Sep 2017 10:12:44 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=722</guid>

					<description><![CDATA[Lately I have been working on a hobby programming project that automatically converts text or web pages into videos. Many functionalities of the software come from an open source project called FFmpeg. It is great for working with video and images. Below you will find the commands and annotations I made over the past few [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Lately I have been working on a hobby programming project that automatically converts text or web pages into videos. Many functionalities of the software come from an open source project called <a href="https://www.ffmpeg.org/">FFmpeg</a>. It is great for working with video and images. Below you will find the commands and annotations I made over the past few weeks about using FFmpeg, which is not always trivial.</p>
<p><strong>Overlay image on video</strong></p>
<p><pre><code>ffmpeg -i input.mp4 -i 1.png -filter_complex &quot;[0:v][1:v] overlay=25:25:enable=&#039;between(t,0,20)&#039;&quot; \
-pix_fmt yuv420p -c:a copy output.mp4</code></pre></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Add audio to video</strong> (if video has audio, needs to map video from input 0 and audio from input 1)</p>
<p><code>ffmpeg -i matrix-16.mp4 -i port-audio.mp3 -map 0:v -map 1:a -acodec aac -strict -2 output.mp4</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Add audio to video: stream copy</strong></p>
<p><code>ffmpeg -i video.avi -i audio.mp3 -codec copy -shortest output.avi</code></p>
<p>Omitting the -map option will use the default stream selection. This will work if your video input has no audio.</p>
<p>This example uses -codec copy to stream copy (no re-encoding; quality is preserved and it is fast).<br />
The -shortest option will make output.avi the same duration as the shortest input.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Add audio to video: re-encode</strong></p>
<p>If your output doesn&#8217;t like the original formats, or if you want to change formats you can specify the encoders:</p>
<p><code>ffmpeg -i video.avi -i audio.mp3 -c:v libx264 -c:a libvorbis -shortest output.mkv</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>To manually choose specific streams</strong></p>
<p>Sometimes the default stream selection won&#8217;t give you the result you want. In this example video.mp4 has video and audio, and audio.m4a only has audio. Use -map to choose video from video.mp4 and audio from audio.m4a:</p>
<p><code>ffmpeg -i video.mp4 -i audio.m4a -map 0:v -map 1:a -c copy -shortest output.mp4</code></p>
<p>-map 0:v – From input 0 (the first input, which is video.mp4) choose the video stream(s).<br />
-map 1:a – From input 1 (the second input, which is audio.m4a) choose the audio stream(s).</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Mixing/combining two audio inputs into one</strong>  (needs tweaking, see below for a better version)</p>
<p>Take video from video.webm, and use the amerge filter to combine the audio from video.webm and audio.oga:</p>
<p><code>ffmpeg -i video.webm -i audio.oga -filter_complex &quot;[0:a][1:a]amerge=inputs=2[a]&quot; -map 0:v -map &quot;[a]&quot; -c:v copy -c:a libvorbis -ac 2 -shortest out.webm</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Generate silent audio</strong></p>
<p>You can use the anullsrc filter to make a silent audio stream. The filter allows you to choose the desired channel layout (mono, stereo, 5.1, etc) and the sample rate.</p>
<p><code>ffmpeg -i video.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -c:v copy -shortest output.mp4</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Concat mp3</strong></p>
<p><code>ffmpeg -i &quot;concat:intro-1.mp3|audio.mp3&quot; -acodec copy output.mp3</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<strong>Overlay many images at the same time</strong></p>
<p><code>ffmpeg -i output.mp4 -i 1.png -i 2.png -i 3.png -i 4.png -i 5.png -i 6.png -i 7.png -i 8.png -filter_complex &quot;[0][1] overlay=0:0:enable=&#039;between(t,4,9)&#039;[v1];[v1][2] overlay=0:0:enable=&#039;between(t,9,15)&#039;[v2];[v2][3] overlay=0:0:enable=&#039;between(t,15,20)&#039;[v3];[v3][4] overlay=0:0:enable=&#039;between(t,20,25)&#039;[v4];[v4][5] overlay=0:0:enable=&#039;between(t,25,31)&#039;[v5];[v5][6] overlay=0:0:enable=&#039;between(t,31,33)&#039;[v6];[v6][7] overlay=0:0:enable=&#039;between(t,33,39)&#039;[v7]; [v7][8] overlay=0:0:enable=&#039;between(t,39,47)&#039;[v8];[v8][1] overlay=0:0:enable=&#039;gt(t,47)&#039;[v9]&quot; -map &quot;[v9]&quot; -map 0:a -pix_fmt yuv420p -c:a copy 1.mp4</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Cut video length at the end</strong></p>
<p><code>ffmpeg -i input.mp4 -c copy -t 00:00:10.0 background.mp4</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Cut beginning and end of video</strong></p>
<p>You can use the -ss option to specify a start timestamp, and the -t option to specify the encoding duration. The timestamps need to be in HH:MM:SS.xxx format or in seconds.</p>
<p>The following would clip the first 30 seconds, and then clip everything that is 10 seconds after that:</p>
<p><pre><code>ffmpeg -i input.wmv -ss 00:00:30.0 -c copy -t 00:00:10.0 output.wmv
ffmpeg -i input.wmv -ss 30 -c copy -t 10 output.wmv</code></pre></p>
<p>Note that -t is an output option and always needs to be specified after -i.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>overlay 2 audio files, adjusting respective volumes</strong></p>
<p><code>ffmpeg -i audio.mp3 -i 2.mp3 -filter_complex &quot;[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=2.5[a1]; [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.3[a2]; [a1][a2]amerge,pan=stereo:c0&lt;c0+c2:c1&lt;c1+c3[out]&quot; -map &quot;[out]&quot; -c:a libmp3lame -q:a 0 -shortest output.mp3</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Concat 2 videos with list.txt</strong></p>
<p><code>ffmpeg -f concat -i list.txt -c copy background.mp4</code></p>
<p>list.txt should be:<br />
file 1.mp4<br />
file 2.mp4</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Adjust framerate and resolution of video</strong></p>
<p><code>ffmpeg -i 3.mp4 -r 25 -s 1920x1080 output.mp4</code></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/list-of-basic-ffmpeg-commands/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Resources and Tutorials for Node.js, Express.js and MondoDB</title>
		<link>https://www.programminglogic.com/resources-and-tutorials-for-node-js-express-js-and-mondodb/</link>
					<comments>https://www.programminglogic.com/resources-and-tutorials-for-node-js-express-js-and-mondodb/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Sun, 13 Nov 2016 09:16:22 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=711</guid>

					<description><![CDATA[Below you&#8217;ll find some useful resources and tutorials for developing Node.js apps with Express.js and MongoDB. MongoDB MongoDB Tutorial Cloud MongoDB Service MLab toArray in MongoDB Node.js/Express.je HTML to Jade/Pug Converter Bcrypt module usage Social authentication with passport]]></description>
										<content:encoded><![CDATA[<p>Below you&#8217;ll find some useful resources and tutorials for developing Node.js apps with Express.js and MongoDB.</p>
<p><strong>MongoDB</strong><br />
<a href="http://blog.modulus.io/mongodb-tutorial">MongoDB Tutorial</a><br />
<a href="https://mlab.com">Cloud MongoDB Service MLab</a><br />
<a href="http://learnwebtutorials.com/using-toarray-in-mongodb">toArray in MongoDB</a></p>
<p><strong>Node.js/Express.je</strong><br />
<a href="http://html2jade.org/">HTML to Jade/Pug Converter</a><br />
<a href="https://www.npmjs.com/package/bcrypt">Bcrypt module usage</a><br />
<a href="http://mherman.org/blog/2013/11/10/social-authentication-with-passport-dot-js/#.WbaNU3XytD8">Social authentication with passport</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/resources-and-tutorials-for-node-js-express-js-and-mondodb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Event-Driven Programming with Node.js</title>
		<link>https://www.programminglogic.com/event-driven-programming-with-node-js/</link>
					<comments>https://www.programminglogic.com/event-driven-programming-with-node-js/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Sat, 08 Oct 2016 10:05:34 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=703</guid>

					<description><![CDATA[Lately I have been playing a lot with Node.js and event-driven programming, and several &#8216;gotcha&#8217; moments occurred. Below you&#8217;ll find of them. Event-Driven Programming: As the name implies, a programming paradigm where the flow of the program is governed by events. There is a main loop monitoring things and triggering the appropriate callbacks. Noje.js: Contrary [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Lately I have been playing a lot with Node.js and event-driven programming, and several &#8216;gotcha&#8217; moments occurred. Below you&#8217;ll find of them.</p>
<p><strong>Event-Driven Programming:</strong> As the name implies, a programming paradigm where the flow of the program is governed by events. There is a main loop monitoring things and triggering the appropriate callbacks.</p>
<p><strong>Noje.js:</strong> Contrary to what some programmers think (I heard it a couple of times), Node.js is NOT a web server. Instead it&#8217;s a JavaScript runtime environment, which uses Google&#8217;s V8 engine to interpret JavaScript. It has an event-driven architecture capable of asynchronous I/O, which makes is quite suitable for web and real time applications.</p>
<p><strong>Callbacks:</strong> A piece of code (usually a function) passed to another piece of code (usually another function, passed as an argument) to be executed at proper time. Useful when you want to specify how a function is supposed to execute part of its task (i.e. how to compare two numbers) or when you want your code to be executed once the function is done and the result available.</p>
<p><strong>Functions as first-class citizens:</strong> In order for callbacks to work, functions need to be first-class citizens in the specific language. This means that they need to support all the operations that other entities support, including being passed as an argument. </p>
<p><strong>Nested callbacks:</strong> If you need to do synchronous stuff with Node.js you might need to nest callbacks to achieve the desired result, and you can store functions inside variables to help. Example:</p>
<p><pre><code>
var updateQuery = function(value){
&nbsp;&nbsp;&nbsp;&nbsp;client.query(&#039;UPDATE T_STATE SET value=&#039;+value,function(err,result){
&nbsp;&nbsp;&nbsp;&nbsp;if(err)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw err;
&nbsp;&nbsp;&nbsp;&nbsp;});
};

client.query(&#039;SELECT value from T_STATE&#039;,function(err,result){
&nbsp;&nbsp;&nbsp;&nbsp;if(err)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw err;
&nbsp;&nbsp;&nbsp;&nbsp;else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var stateValue =&nbsp;&nbsp;result.rows[0].value;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stateValue++;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateQuery(stateValue);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
});&nbsp;&nbsp; 
</code></pre></p>
<p><strong>Node.js and callbacks:</strong> Callbacks are everywhere in Node.js and related libraries (i.e., Express.js). Usually those callbacks handle error first and then execute the specific code.</p>
<p><strong>Stack, Heap, Queue, Event Loop:</strong> JavaScript function calls get a stack frame on the <strong>stack</strong> (with arguments, local variables, etc.). Objects are allocated in the <strong>heap</strong>. When you call web APIs (e.g., XMLHttpRequest or setTimeout) those go in the <strong>queue</strong> (as messages). When events with listeners happen, they also go into the queue. Whenever the stack is free, the <strong>event loop</strong> will get the first message from the queue and put it on the stack for execution.</p>
<p>Useful resources:</p>
<p><a href="http://code.danyork.com/2011/01/25/node-js-doctors-offices-and-fast-food-restaurants-understanding-event-driven-programming/">Event-Driven programming with analogies</a><br />
<a href="http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/">Understand the event loop</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/event-driven-programming-with-node-js/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Deploy a Node.js App to Heroku</title>
		<link>https://www.programminglogic.com/how-to-deploy-a-node-js-app-to-heroku/</link>
					<comments>https://www.programminglogic.com/how-to-deploy-a-node-js-app-to-heroku/#comments</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Thu, 08 Sep 2016 02:52:20 +0000</pubDate>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=690</guid>

					<description><![CDATA[Below you&#8217;ll find the basic steps to deploy a Node.js (should apply to other languages and frameworks as well) on Heroku. It assumes you have Git and Heroku toolbelt installed. You can view a more detailed tutorial here. 1. Create the app locally (you can view a &#8220;Hello World&#8221; example here) 2. git init 3. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Below you&#8217;ll find the basic steps to deploy a Node.js (should apply to other languages and frameworks as well) on Heroku.</p>
<p>It assumes you have Git and Heroku toolbelt installed. You can view a <a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs">more detailed tutorial here</a>.</p>
<p>1. Create the app locally (you can view a <a href="https://github.com/DanielScocco/hello-world-node-heroku">&#8220;Hello World&#8221; example here</a>)<br />
2. git init<br />
3. heroku create appname<br />
4. git push heroku master<br />
5. heroku ps:scale web=1</p>
<p>You can then use &#8216;heroku open&#8217; to launch and test it. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/how-to-deploy-a-node-js-app-to-heroku/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Git Basic Commands</title>
		<link>https://www.programminglogic.com/git-basic-commands/</link>
					<comments>https://www.programminglogic.com/git-basic-commands/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Wed, 07 Sep 2016 15:52:59 +0000</pubDate>
				<category><![CDATA[Tools]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=686</guid>

					<description><![CDATA[Git is one of the most popular version control systems out there. Below you&#8217;ll find the basic commands you need to get started with it. Note: One important aspect to understand about Git is that it thinks about data as snapshots of files over time. Every commit will generate a new snapshot, that is independent [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Git is one of the most popular version control systems out there. Below you&#8217;ll find the basic commands you need to get started with it.</p>
<p><strong>Note:</strong> One important aspect to understand about Git is that it thinks about data as snapshots of files over time. Every commit will generate a new snapshot, that is independent of previous ones. This is very different from the approach used by most other version control systems, where data is thought as files and changes to those files over time.</p>
<p><strong>1. Installing Git on Linux</strong></p>
<p><code>sudo apt-get install git-all</code></p>
<p><strong>2. Creating a Git Repository</strong></p>
<p>There are two ways to create a new Git repository. You can either use an existing folder/project, or clone one from a remote server. If you are using an existing folder, go inside it and type</p>
<p><code>git init</code></p>
<p>If you want to clone a repository:</p>
<p><code>git clone https://github.com/project/</code></p>
<p><strong>3. Getting information about the repository</strong></p>
<p><code>git status</code></p>
<p><strong>4. Tracking a file</strong></p>
<p>If you create a new file, it won&#8217;t be tracked by Git immediately. You need to use the &#8216;add&#8217; command to do so.</p>
<p><code>git add file.c</code></p>
<p><strong>5. Staging files</strong></p>
<p>Once you change files, Git will know. But that doesn&#8217;t mean it will automatically use those modified versions on the next commit. If you want to do so, you need to &#8216;stage&#8217; the modified file. You do so using the same &#8216;add&#8217; command.</p>
<p><code>git add file.c</code></p>
<p><strong>6. Committing Changes</strong></p>
<p><code>git commit</code></p>
<p>or if you want to add a message to the commit:</p>
<p><code>git commit -m &quot;bug fix 1&quot;</code></p>
<p>or if you want to include even files that weren&#8217;t staged with the &#8216;add&#8217; command:</p>
<p><code>git commit -a</code></p>
<p><strong>7. Removing files</strong></p>
<p><code>git rm file.c</code></p>
<p><strong>8. View changes over time</strong></p>
<p><code>git log</code></p>
<p><strong>9. Getting a remote project</strong></p>
<p><code>git fetch [remote-project]</code></p>
<p>or if you want to get and merge:</p>
<p><code>git pull [remote-project]</code></p>
<p><strong>10. Pushing your project to remove server</strong></p>
<p><code>git push [remote-project] [branch]</code></p>
<p>usually this will look like </p>
<p><code>git push origin master</code></p>
<p>Because when you clone a project Git automatically calls the remote project &#8216;origin&#8217;.</p>
<p><strong>Small Teams Working on the Same Git Project</strong><br />
&#8211; No one pushes to master.<br />
&#8211; For every feature (or update on a feature), create new branch.<br />
&#8211; Send pull request for reviewing (one of us is the reviewer).<br />
&#8211; Merge pull request into master.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/git-basic-commands/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Facebook Webhook Integration Code in PHP</title>
		<link>https://www.programminglogic.com/facebook-webhook-integration-code-in-php/</link>
					<comments>https://www.programminglogic.com/facebook-webhook-integration-code-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Wed, 07 Sep 2016 10:38:51 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=683</guid>

					<description><![CDATA[Many types of applications that interact with Facebook will need to use webhooks. Messenger chat bots are an example. If you follow Facebook&#8217;s setup guide, you&#8217;ll notice that the example provided to activate a webhook for the first time is in Node.js: &#160;&#160;app.get(&#039;/webhook&#039;, function (req, res) { &#160;&#160;&#160;&#160;if (req.query[&#039;hub.verify_token&#039;] === &#039;YOUR_VERIFY_TOKEN&#039;) { &#160;&#160;&#160;&#160;&#160;&#160;res.send(req.query[&#039;hub.challenge&#039;]); &#160;&#160;&#160;&#160;} else [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Many types of applications that interact with Facebook will need to use webhooks. Messenger chat bots are an example.</p>
<p>If you follow <a href="https://developers.facebook.com/docs/messenger-platform/product-overview/setup">Facebook&#8217;s setup guide</a>, you&#8217;ll notice that the example provided to activate a webhook for the first time is in Node.js:</p>
<p><pre><code>&nbsp;&nbsp;app.get(&#039;/webhook&#039;, function (req, res) {
&nbsp;&nbsp;&nbsp;&nbsp;if (req.query[&#039;hub.verify_token&#039;] === &#039;YOUR_VERIFY_TOKEN&#039;) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.send(req.query[&#039;hub.challenge&#039;]);
&nbsp;&nbsp;&nbsp;&nbsp;} else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.send(&#039;Error, wrong validation token&#039;);&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;});</code></pre></p>
<p>I saw on online forums many people looking for a PHP version of that code, so here you go:</p>
<p><pre><code>&lt;?php

$challenge = $_REQUEST[&#039;hub_challenge&#039;];
$verify_token = $_REQUEST[&#039;hub_verify_token&#039;];

if ($verify_token === &#039;my_token&#039;) {
&nbsp;&nbsp;&nbsp;&nbsp;echo $challenge;
}
else{
&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Error, wrong validation token&quot;;
}

?&gt;</code></pre></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/facebook-webhook-integration-code-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>JSONP Example &#8211; Getting Data from Another Domain with JavaScript</title>
		<link>https://www.programminglogic.com/jsonp-example-getting-data-from-another-domain-with-javascript/</link>
					<comments>https://www.programminglogic.com/jsonp-example-getting-data-from-another-domain-with-javascript/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Sat, 03 Sep 2016 00:53:44 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=675</guid>

					<description><![CDATA[As you probably know, you can&#8217;t send AJAX (XMLHttpRequest) requests to another domain. Browsers block it because of the Same Origin Policy, a rule used to make sure that a malicious script won&#8217;t be able to access data on other pages. This can be a problem, however, if you need to load data for a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As you probably know, you can&#8217;t send AJAX (XMLHttpRequest) requests to another domain. Browsers block it because of the <em>Same Origin Policy</em>, a rule used to make sure that a malicious script won&#8217;t be able to access data on other pages.</p>
<p>This can be a problem, however, if you need to load data for a widget from another domain. For instance, suppose you are developing a widget that your partners will use on their websites and it will load data from your server.</p>
<p>A really clever solution is called <strong>JSONP</strong>, which stands for &#8220;JSON with Padding.&#8221; It works by &#8220;exploiting&#8221; the fact that &#60;script&#62; tags can load files from other domains.</p>
<p>Here&#8217;s a simple example of how it works:</p>
<p><strong>1. Create your HTML file (On Domain A)</strong></p>
<p><pre><code>&lt;html&gt;
&lt;body&gt;
&lt;h1 id=&quot;maintitle&gt;&lt;h1&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></p>
<p>As you can see, it has no title. We are going to get the title from another website, and put it there using JavaScript.</p>
<p><strong>2. Create a JavaScript function to change the title (On Domain A)</strong></p>
<p><pre><code>&lt;html&gt;
&lt;body&gt;
&lt;h1 id=&quot;maintitle&gt;&lt;h1&gt;
&lt;script&gt;&nbsp;&nbsp;
function changeTitle(data){
&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(&quot;maintitle&quot;).innerHTML = data.title;
};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></p>
<p>Notice that this functions receives a parameter &#8220;data&#8221; which contains the title, and then changes it on the HTML.</p>
<p><strong>3. Create the server side script that returns the data (On Domain B)</strong></p>
<p><pre><code>&lt;?php
if($_GET[&#039;callback&#039;]){
&nbsp;&nbsp;$f_name = $_GET[&#039;callback&#039;];
&nbsp;&nbsp;echo &quot;$f_name({&#039;title&#039;:&#039;Hello World!&#039;});&quot;;&nbsp;&nbsp; 
}
else{
&nbsp;&nbsp;echo &quot;Error: You must pass a callback parameter&quot;;
}
?&gt;</code></pre></p>
<p>This script checks whether a GET parameter called &#8216;callback&#8217; was provided. In positive case, it returns a JavaScript function named after that parameter, and the title as data (in this example the title is &#8220;Hello World&#8221;). </p>
<p>Now suppose we put that script on <em>serverdomain.com/server.php</em>. If we opened <em>serverdomain.com/server.php?callback=ChangeTitle</em> the server would send back the following:</p>
<p><code>ChangeTitle({&#039;title&#039;:&#039;Hello World&#039;});</code></p>
<p>This is the same name of the JavaScript function we created on step 2. That is no coincidence. You are going to see why now.</p>
<p><strong>4. Use another &#60;script&#62; tag to load the data from the other server (On Domain A)</strong></p>
<p><pre><code>&lt;html&gt;
&lt;body&gt;
&lt;h1 id=&quot;maintitle&gt;&lt;h1&gt;
&lt;script&gt;&nbsp;&nbsp;
function changeTitle(data){
&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(&quot;maintitle&quot;).innerHTML = data.title;
};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/script&gt;
&lt;script src=&quot;http://serverdomain.com/server.php?callback=ChangeTitle&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></p>
<p>The second &#60;script&#62; tag will ping our server and essentially load this code:</p>
<p><code>ChangeTitle({&#039;title&#039;:&#039;Hello World&#039;});</code></p>
<p>This will call the ChangeTitle function defined on the first &#60;script&#62; tag with our title as a parameter, and that function will then change the title of the HTML.</p>
<p>Nice huh?</p>
<p><strong>5. Making the Request Dynamically </strong></p>
<p>The example above makes the request by placing a &#60;script&#62; manually on the HTML of the page. You can also do that dynamically with JavaScript, which becomes quite handy for dynamic web applications:</p>
<p><pre><code>
function myFunction(data)
{
&nbsp;&nbsp;&nbsp;&nbsp;//do stuff
}

var script = document.createElement(&#039;script&#039;);
script.src = &#039;http://example.com/?callback=myFunction&#039;;
document.getElementsByTagName(&#039;head&#039;)[0].appendChild(script);</code></pre></p>
<p>The code below will also work on newer browsers:</p>
<p><code>document.head.appendChild(script) </code></p>
<p><strong>Common problems:</strong></p>
<p>1. Notice that both domains must be using the same protocol (HTTP or HTTPS), else you&#8217;ll get an error.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/jsonp-example-getting-data-from-another-domain-with-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Modern JavaScript Development</title>
		<link>https://www.programminglogic.com/modern-javascript-development/</link>
					<comments>https://www.programminglogic.com/modern-javascript-development/#respond</comments>
		
		<dc:creator><![CDATA[Daniel Scocco]]></dc:creator>
		<pubDate>Thu, 23 Jun 2016 10:29:51 +0000</pubDate>
				<category><![CDATA[Tools]]></category>
		<guid isPermaLink="false">http://www.programminglogic.com/?p=672</guid>

					<description><![CDATA[It looks like JavaScript is taking the crown from Ruby for modern web development. I never used it in the backend, so I was curious to research about the libraries and frameworks that the cool kids are using these days. Here are some of them: node.js &#8211; event-driven runtime environment for developing server-side applications . [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>It looks like JavaScript is taking the crown from Ruby for modern web development. I never used it in the backend, so I was curious to research about the libraries and frameworks that the cool kids are using these days. Here are some of them:</p>
<p><strong>node.js</strong> &#8211; event-driven runtime environment for developing server-side applications . Allows you to develop in JS, and it&#8217;s quite fast. It also handles concurrent connections quite efficiently.</p>
<p><strong>express.js</strong> &#8211; minimalist server-side web framework for node.js</p>
<p><strong>React</strong> &#8211; javascript library for building user interfaces</p>
<p><strong>angular.js</strong> &#8211; client-side, web applications framework, especially suitable for single-page applications</p>
<p><strong>knex.js</strong> &#8211; SQL query builder for JavaScript</p>
<p><strong>backbone.js</strong> &#8211; javascript library with a RESTful JSON interface, based on MVP</p>
<p><strong>socket.io</strong> &#8211; javascript library for real time web apps. enables biderection communication between server and client</p>
<p>As for databases, MySQL seems to still be the default choice, by MongoDB and PostgreSQL are following closely.</p>
<p>Here&#8217;s an interesting post about the topic (though from 2014): <a href="http://codingvc.com/which-technologies-do-startups-use-an-exploration-of-angellist-data">Which Technologies Do Startups Use? An Exploration of AngelList Data</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.programminglogic.com/modern-javascript-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
