Skip to content

Instantly share code, notes, and snippets.

@tamboer
tamboer / decimalToTime.js
Last active December 27, 2015 11:09
convert decimal to time.js
Ho to transform a decimal time interval (for example, 1.074 minutes) into its equivalent 'mm:ss' value.
Here is some JavaScript that will do what you are asking:
function minTommss(minutes){
var sign = minutes < 0 ? "-" : "";
var min = Math.floor(Math.abs(minutes))
var sec = Math.floor((Math.abs(minutes) * 60) % 60);
return sign + (min < 10 ? "0" : "") + min + ":" + (sec < 10 ? "0" : "") + sec;
}
<h1>Alert</h1>
<p>Bootstrap JS</p>
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>
<p></p><a ng-click="alert=true">Open Alert (AngularJS)</a></p>
<div class="alert fade" ng-class="{in:alert}">
<button type="button" class="close" ng-click="alert=false">×</button>
@tamboer
tamboer / SLOC.TXT
Last active December 25, 2015 01:49
Count lines of code SLOC - Source Lines of Code
http://stackoverflow.com/questions/1358540/how-to-count-all-the-lines-of-code-in-a-directory-recursively
find . -name '*.php' | xargs wc -l
==================================
If you are looking to find filenames then use "find" like this:
find /directory/path/to/search -name "filename or part thereof"
@tamboer
tamboer / rsync.txt
Last active December 22, 2015 16:39
rsync
rsync -avh /tmp/foo/ root@host2:/tmp/bar
http://www.evbackup.com/support-commonly-used-rsync-arguments/
I am having Folder A on my computer which is constantly updated with content.
Another Folder B is used for backup purpose which is on external HDD.
Now what I expect is that whatever extra which is present in folder A should go to folder B.
However something which is present in B and NOT in A ""shall NOT be copied to A"".
@tamboer
tamboer / cli_tools
Created September 5, 2013 08:59
rsync curl cli tools
cURL
Curl is a command line utility used for multi purpose, basically it is defined as the tool that can transfer data using various protocols such as DICT, FILE, FTP, FTPS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet, Gopher, TFTP and much more. Curl supports SSL certificates and HTTP PUT or HTTP POST features too. In a simple statement we can say that curl can get information and send information via one of the protocol mentioned above. How is it useful for web developers? Curl can send response headers of any website, it can be used to find out the look-up time, connect time or generally saying to check the time consumed in order to reach a website. Its uses are unlimited and it comes as a default software in most of the Linux operating systems. In case if it is not available, you can install it easily with this command.
Install curl in Linux
$sudo apt-get install curl
$su -c "yum install curl"
RSYNC
@tamboer
tamboer / shell_scripting
Last active September 13, 2016 15:31
shell scripting
============================================================================
printenv = print environment variables or what php calls global variables
TERM=xterm
SHELL=/bin/bash
USER=user
DEFAULTS_PATH=/usr/share/gconf/xubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-xubuntu:/etc/xdg:/etc/xdg
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
@tamboer
tamboer / batch-image-resize.txtx
Created September 1, 2013 19:31
batch image resize - cli shell tasks
# apt-get install imagemagick
Once installed you will have multiple image processing tools available to our disposal, such as convert, identify and etc.
identify command will help you to get some image information and convert will help you to convert images between hundreds of different image formats as well as it will easily resize any image submitted as an argument.
Let's suppose that our current working directory contains multiple image files with extension *.jpg . To resize all images to a half size of their original size we can combine bash for loop and convert command together in a following manner:
Code:
$ for i in $( ls *.jpg); do convert -resize 50% $i re_$i; done
@tamboer
tamboer / cron_jobs_general.txt
Last active December 22, 2015 02:48
cron jobs general
=======================
tail -f /var/log/syslog
=======================
#min hour day month weekday command
*/1 * * * * <your command>
@tamboer
tamboer / xml_array_to_xml.php
Last active December 22, 2015 00:09
xml array to xml
<?php
function createXml($posts, $format = null)
{
/* output in necessary format */
if ($format == 'json') {
header('Content-type: application/json');
echo json_encode(array('posts' => $posts));
} else {
header('Content-type: text/xml');
@tamboer
tamboer / git change remote.txt
Created August 29, 2013 11:44
git change remote
git remote remove origin
git remote add origin git@example.com:name_of_project.git
git fetch
git merge ...