Monday, September 7, 2015

Mac Tricks & Hacks


  1. NTFS Support
    1. Install ntfs-3g-2010.10.2-macosx.dmg & Restart
    2. If it throws error, Install macfuse-core-10.5-2.1.9.dmg
  2. Hide Apps from Application Switcher
    1. Sometime you want to hide application e.g. torrent client activity when pressing Cmd+Tab
    2. Add the following in the respective Info file. E.g. In /Applications/uTorrent.app/Contents/Info.plist
    3. <key> LSUIElement </key> <string> 1 </string>
  3. Default Vim Syntax Highlight
    1. echo "syntax on" >> ~/.vimrc
  4. Default color Theme
    1. echo "colo desert" >> ~/.vimrc
  5. Default intend
    1. echo "filetype plugin indent on" >> ~/.vimrc
  6. ntfs support in mac
    1. Create /etc/fstab and write
      1. LABEL=DRIVE_NAME none ntfs rw,auto,nobrowse
    2. It is ready. However, If finder doesn't show in finder, use open DIR_NAME

Wednesday, January 28, 2015

Nginx performance optimization


  1. Enable woff compression in Nginx
    1. Add Mime type - /etc/nginx/mime.types
      1. application/font-woff                   woff;
    2. Add gzip compression for fonts - /etc/nginx/nginx.conf
      1. gzip_types  application/font-woff
  2. Administration
    1. Reload - sudo service nginx reload
    2. Start - sudo nginx
    3. stop - sudo nginx -s stop

Tuesday, September 23, 2014

High Performance Web Sites - Best Practices

Client Side Performance - Best Practices

80% of the end-user response time is spent on the front-end.Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. This document contains a number of best practice rules for making web pages fast. Most of the suggestions improve the performance from the client side i.e. once html is downloaded.

Best Practices

Here are best practices segregated into different categories.

1. Content


1.1 Make Fewer HTTP Requests

Reducing the number of components in turn reduces the number of HTTP requests required to render the page.
  • Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.
  • CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.
  • Inline images use the data: URL scheme to embed the image data in the actual page. This can increase the size of your HTML document. Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages. Inline images are not yet supported across all major browsers.

1.2 Reduce DNS Lookups

The Domain Name System (DNS) maps hostnames to IP addresses. Every DNS lookup typically takes 20-120 milliseconds for DNS to lookup the IP address for a given hostname. The browser can't download anything from this hostname until the DNS lookup is completed.
  • Reducing the number of unique hostnames has the potential to reduce the amount of parallel downloading that takes place in the page.
  • Caution : Avoiding DNS lookups cuts response times, but reducing parallel downloads may increase response times.
  • Guideline is to split these components across at least two but no more than four hostnames

1.3 Make Ajax Cacheable

One of the cited benefits of Ajax is that it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server
  • Add an Expires or a Cache-Control Header to make the responses cacheable to improve the performance of Ajax.

1.4 Postload Components

You can take a closer look at your page and ask yourself: "What's absolutely required in order to render the page initially?". The rest of the content and components can wait.
  • JavaScript is an ideal candidate for splitting before and after the onload event
    • Example if you have JavaScript code and libraries that do drag and drop and animations, those can wait, because dragging elements on the page comes after the initial rendering
  • Post-load hidden content e.g. that appears after a user action
  • Images below the fold (you have to scroll to see that)

1.5 Preload Components

Preload may look like the opposite of post-load, but it actually has a different goal.
  • Preload components when the browser is idle and request components (like images, styles and scripts) you'll need in the future. This way when the user visits the next page, you could have most of the components already in the cache and your page will load much faster for the user.
There are actually several types of preloading:
  1. Unconditional preload - as soon as onload fires, you go ahead and fetch some extra components.
  2. Conditional preload - based on a user action you make an educated guess where the user is headed next and preload accordingly.
  3. Anticipated preload - preload in advance before launching a redesign or pushing new Build into production

1.6 Reduce the Number of DOM Elements

It makes a difference if you loop through 500 or 5000 DOM elements on the page when you want to add an event handler. It Slows!
  • Check : Are you using nested tables for layout purposes? Are you throwing in more
    s only to fix layout issues?
  • The number of DOM elements is easy to test, just type in Firebug's console: document.getElementsByTagName('*').length
  • Even pretty busy page shouldn't have more than 800-900 DOM elements.

1.7 Split Components Across Domains

Splitting components allows you to maximize parallel downloads.
  • Use not more than 2-4 domains because of the DNS lookup penalty.
  • Example, you can host your HTML and dynamic content on www.wamart.com and split static components between i1.walmart.com and i2.walmart.com

1.8 Minimize Number of iframes

Iframes allow an HTML document to be inserted in the parent document. It's important to understand how iframes work so they can be used effectively.
  • iframe pros:
    1. Helps with slow third-party content like badges and ads
    2. Security sandbox
    3. Download scripts in parallel
  • iframe cons:
    1. Costly even if blank
    2. Blocks page onload
    3. Non-semantic

1.9 Avoid 404s

HTTP requests are expensive so making an HTTP request and getting a useless response (i.e. 404 Not Found) is totally unnecessary and will slow down the user experience without any benefit.
  • Even worse when the link to an external JavaScript is wrong and the result is a 404
    • First, this download will block parallel downloads.
    • Second, the browser may try to parse the 404 response body as if it were JavaScript code, trying to find something usable in it

1.10 Avoid Redirects

Redirects are accomplished using the 301 and 302 status codes.
  • Redirects slow down the user experience. Inserting a redirect between the user and the HTML document delays everything in the page since nothing in the page can be rendered and no components can start being downloaded until the HTML document has arrived.

2. Server


2.1 Use a CDN

The user's proximity to your web server has an impact on response times. A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content more efficiently to users.
  • It may improve the end-user response times by 20% or more

2.2 Add Expires or Cache-Control Header

A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable.
  • This avoids unnecessary HTTP requests on subsequent page views.
  • Very simple to configure. E.g. in Apache httpd.conf ExpiresDefault "access plus 10 years"
  • The number of page views with a primed cache is 70-80% typically for a eCommerce site like walmart.com
  • Caution : if you use a far future Expires header you have to change the component's filename whenever the component changes e.g. use version like asda_v1.2.js

2.3 Gzip Components

The time it takes to transfer an HTTP request and response across the network can be significantly reduced by enabling compression for textual components ( e.g. JavaScripts, CSS, HTML)
  • Compression reduces response times by reducing the size of the HTTP response.
  • Starting with HTTP/1.1, web clients supports compression with the Accept-Encoding header in the HTTP request. Accept-Encoding: gzip, deflate
  • Gzipping generally reduces the response size by about 70%
  • Caution : Image and PDF files should not be gzipped because they are already compressed. Trying to gzip wastes CPU

2.4 Configure ETags

Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server.
  • ETags won't match when a browser gets the original component from one server and later tries to validate that component on a different server, a too common situation on Web sites that use a cluster of servers to handle requests
  • If you have multiple servers hosting your web site, users may be getting slower pages, servers may have a higher load & consuming greater bandwidth, and proxies aren't caching the content efficiently.
    • Even if your components have a far future Expires header, a conditional GET request is still made whenever the user hits Reload or Refresh.
  • Very simple to configure. E.g. in Apache httpd.conf FileETag none

2.5 Flush Buffer Early

When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page and serve.
  • During this time, the browser is idle as it waits for the data to arrive.
  • Use some kind of flush buffer mechanism so that the browser can start fetching components while your backend is busy.
    • E.g. in PHP, flush() can be used.
  • A good place to consider flushing is right after the HEAD so that browser can fetch CSS & JavaScript files in parallel.

2.6 Use GET for Ajax Requests

When using XMLHttpRequest, POST is implemented in the browsers as a two-step process: sending the headers first, then sending data.
  • It's best to use GET, which only takes one TCP packet to send (unless you have a lot of cookies).
  • Also as per W3C standards, GET is meant for retrieving information, so it makes sense (semantically) to use GET when you're only requesting data, as opposed to sending data to be stored server-side.
  • Caution : The maximum URL length in IE is 2K, so if you send more than 2K data you might not be able to use GET.

2.7 Avoid Empty Image src

Without a purpose, browser makes another request to the server.
  • Browser beahavior:
    • Internet Explorer makes a request to the directory in which the page is located.
    • Safari and Chrome make a request to the actual page itself.
    • Firefox 3 and earlier versions behave the same as Safari and Chrome, but version 3.5 addressed this issue[bug 444931] and no longer sends a request.
    • Opera does not do anything when an empty image src is encountered.
  • Possible reason, when creating the image dynamiccaly, and value is not available
    • E.g. Using Javascript, var img = new Image(); img.src = '';

3.1 Reduce Cookie Size

Information about cookies is exchanged in the HTTP headers between web servers and browsers. It's important to keep the size of cookies as low as possible to minimize the impact on the user's response time. Few suggestions:
  • Eliminate unnecessary cookies
  • Keep cookie sizes as low as possible to minimize the impact on the user response time
  • Be mindful of setting cookies at the appropriate domain level so other sub-domains are not affected
  • Set an Expires date appropriately. An earlier Expires date or none removes the cookie sooner, improving the user response time

3.2 Use Cookie-Free Domains for Components

Serving static components usually doesn't require a cookie. Therefore, if static components get served from main domain e.g. walmart.com, it will carry unnecessary load of cookies.
  • Serve components for other domains e.g. i1.walmart.com, or better to be i1.wmcdn.com similar to YouTube which uses ytimg.com, or Amazon uses images-amazon.com

4. CSS


4.1 Put Stylesheets at Top

Moving stylesheets to the document HEAD makes pages appear to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively.
  • Problem with putting stylesheets near the bottom of the document is that
    1. it prohibits progressive rendering in many browsers, including Internet Explorer.
    2. These browsers block rendering to avoid having to redraw elements of the page if their styles change. The user may stuck sometimes viewing a blank white page.

4.2 Avoid CSS Expressions

CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically.
  • Example : background color could be set to alternate every hour using CSS expressions: background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );
  • Problem with expressions is that they are evaluated more frequently than most people expect.
    1. They get evaluated when the page is rendered or resized or scrolled or even when the user moves the mouse over the pag
    2. Moving the mouse around the page can easily generate more than 10,000 evaluations.

4.3 Choose Over @import

One of the previous best practices states that CSS should be at the top in order to allow for progressive rendering. However, @import doesn't behave the same as does.
  • Problem : In IE @import behaves the same as using at the bottom of the page, so it's best not to use it.

4.4 Avoid Filters

The IE-proprietary AlphaImageLoader filter aims to fix a problem with semi-transparent true color PNGs in IE versions < 7
  • Problem with this filter is that:
    1. it blocks rendering and freezes the browser while the image is being downloaded
    2. It also increases memory consumption and is applied per element, not per image, so the problem is multiplied.
  • The best approach is to avoid AlphaImageLoader completely and use gracefully degrading PNG8 instead, which are fine in IE. If you absolutely need AlphaImageLoader, use the underscore hack _filter as to not penalize your IE7+ users.

5. JavaScript


5.1 Put Scripts at Bottom

  • The problem caused by scripts is that they block parallel downloads
    • If a script is downloading, the browser won't start any other downloads, even on different hostnames.
  • If scripts can't be moved to lower of the page, use deferred scripts, which indicates that the script does not contain document.write, and is a clue to browsers to continue rendering
    • Unfortunately, Firefox doesn't support the DEFER attribute

5.2 Make JavaScript and CSS External

For eCommerce sites like walmart.com, HTML is always dynamic in nature. Javascipts & CSS contents being considered static instead.
  • Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser
  • JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested, resulting in
    1. Increased HTML size which can't be cached
    2. Increased wait time due to rendering can not be started until HTML get downloaded.
    3. Probable Increased wight as it can't be uses on other pages even if required, so need to download again.

5.3 Minify JavaScript and CSS

Minification is the practice of removing unnecessary characters from code to reduce its size thereby improving load times.
  • Minification removes all comments & unneeded white space characters (space, newline, and tab)
  • Further Obfuscation can be applied within minification, to reduce size further.
  • In a survey of ten top U.S. web sites, minification achieved a 21% size reduction (25% with obfuscation)
  • E.g. use YUI Compressor  
    • java -jar yuicompressor3..0.jar -type [js | css] [filename] -o [output filename]

5.4 Remove Duplicate Scripts

It hurts performance to include the same JavaScript file twice in one page and sad part is this isn't as unusual.
  • E.g. Some markets having 3 duplicates of jquery.js being downloaded thru different URLs and one with different version (served one from each http, https & google).

5.5 Minimize DOM Access

Accessing DOM elements with JavaScript is slow so in order to have a more responsive page, you should:
  • Cache references to accessed elements
  • Update nodes "offline" and then add them to the tree
  • Avoid fixing layout with JavaScript

5.6 Develop Smart Event Handlers

Sometimes pages feel less responsive because of too many event handlers attached to different elements of the DOM tree which are then executed too often
  • Use event delegation e.g. If you have 10 buttons inside a div, attach only one event handler to the div wrapper, instead of one handler for each butto

6. Images


6.1 Optimize Images

Optimize images by compressing them in lossless fashion (without compromising any visual quality) to reduce page weight.
  • Use Smushit or ImageMagick for lossless compression.

6.2 Optimize CSS Sprites

  • Don't leave big gaps between the images in a sprite.
  • Combining similar colors in a sprite helps you keep the color count low, ideally under 256 colors so to fit in a PNG8.
  • Arranging the images in the sprite horizontally as opposed to vertically usually results in a smaller file size.

6.3 Do Not Scale Images in HTML

Don't use a bigger image than you need just because you can set the width and height in HTML.

6.4 Make favicon.ico Small and Cacheable

  • Since it's on the same server, cookies are sent every time it's requested
  • It also interferes with the download sequence, e.g. in IE when you request extra components in the onload, the favicon will be downloaded before these extra components.
  • It should be small, preferably under 1K.
  • Set Expires header with what you feel comfortable since you cannot rename it if you decide to change it.

7. Mobile


7.1 Keep Components Under 25 KB

This restriction is related to the fact that iPhone won't cache components bigger than 25K. Note that this is the uncompressed size. This is where minification is important because gzip alone may not be sufficient.

7.2 Pack Components Into a Multipart Document

Packing components into a multipart document is like an email with attachments, it helps you fetch several components with one HTTP request (remember: HTTP requests are expensive).
  • Caution : When you use this technique, first check if the user agent supports it (iPhone does not).

Performance Tools

Note : Getting a good grade doesn't mean good performance, rather it tells that standards are being followed for better performance.

YSlow - The Tool

YSlow tool is used to analyze a web pages and get a report on why the web page is slow based on the best practices for high performance web sites. YSlow is a Firefox add-on integrated with the Firebug web development tool, and Grade pages on the basis of certain performance rules.

Google Page Speed

Page sppeed is similar to YSlow, except few more suggestions regarding client side performance optimizations.

Advanced (more)

Useful Reads

Wednesday, September 17, 2014

Hacking Sessions to Hack into others account

Recently I've successfully hacked into somebody else account as an white collar using Session Hijacking on one of the Highest Traffic eCommerce Site. So thought of sharing for study purpose only.

What is session hijacking?
"Session hijacking (a.k.a cookie hijacking) is the exploitation of a valid computer session—sometimes also called a session key—to gain unauthorized access to information or services in a computer system."



E.g. on an typical eCommerce Site, a user can Hack into anybody's account using SessionId, and access Confidential user information like:
  • All Credit Cards details, All Postal Addresses, Mobile Numbers, Email address, All orders, shopping & favorites lists etc.
Further a hacker can,
  • Get the order at his place by changing address,
  • Place new order or cancel any genuine order
  • Call the customer pretending Company Representative to extract further information.

How the hell this haapens!
  1. Login to 2 different browsers on different or same machines (say user A & B).
  2. Pick up user B' Session Id value
  3. Edit user A's SessionId with the above Value (cookie editor!)
  4. BOOM!!! user "A" can access all the B's information.

What how the real hacker can get a session id?
  1. User can sniff the session Ids of other users, and he can do the rest.
  2. Brute force session id generation, and the rest you know already, don't you!

Be Proactive rather than reactive! 
Here are some examples of usual defense-in-depth strategies:
  1. Security of HTTP (HTTPS)
  2. Secure randomization (leading to extreme difficulty in guessing)
  3. Re-authentication (reenter password) for accessing sensitive information
  4. Regenerating the session id after a successful login to prevent session fixation
  5. Secondary checks against the identity of the user like check same IP, user agent
  6. Two factor authentication
Please note, you have to find out first the target site which is vulnerable to the above security threat

Resources:
  1. https://www.owasp.org/index.php/Session_Management_Cheat_Sheet
  2. http://technet.microsoft.com/en-us/magazine/2005.01.sessionhijacking.aspx 
  3. http://googlewebmastercentral.blogspot.com/2014/08/https-as-ranking-signal.html 
  4. http://techcrunch.com/2012/11/18/facebook-https/

Wednesday, May 14, 2014

MySQL Quick Hacks & problem solving

Few day to day MySQL working, administration, hacking and problem solving tips.

  1. ERROR 1 (HY000): Can't create/write to file '/tmp/#sql****.MYI' (Errcode: 13) 
    1. Solution : This is basically due to messed up /tmp permissions
      1. chown root:root /tmp
      2. chmod 1777 /tmp
      3. /etc/init.d/mysqld restart

Sunday, March 9, 2014

Free Microsoft Office Online, better than Google Docs!

Microsoft’s Office Online is a completely free, web-based version of Microsoft Office. This online office suite is clearly competing with Google Docs, but it’s also a potential replacement for the desktop version of Office.


Some advantages (similar to Google Docs/Drive)
  • Browser based, so can access from anywhere, from any OS
  • Can be shared with others easily
  • Better collaboration features
  • Free!


You can create Word, OneNote, PowerPoint, Excel, Calendar etc along with having 7GB free space on OneDrive.

Free Templates (Project Track, calendar, business proposals, memo, resume, 12 month time line etc)

Browse your created documents :



Beside: here you can access some GoogleDocs public templates as well,

Tuesday, October 29, 2013

Hacking Google : Tips & Tricks


  • Free Downloads of any type
    • Ever needed an old Android app but couldn't find the APK for what you were looking for? Or wanted an MP3 but couldn't find the right version? Google has a few search tools that, when used together, can unlock a plethora of downloads: inurl, intitle, and filetype. For example, to find free Android APKs, you'd search for -inurl:htm -inurl:html intitle:"index of" apk to see site indexes of stored APK files
      • -inurl:htm -inurl:html intitle:"index of" apk
      • intitle:"index of" downloads
      • filetype:pdf Javascript
  • Search Product, Recipes, and More with Reverse Image Search
    • With Google, you can just drop a picture into Google Images and it'll search for similar pictures. 
  • Get google cache copy directly
    • We all know Google Cache can be a great tool, but there's no need to search for the page and then hunt for that "Cached" link: just type cache: before that site's URL
      • cache:http://vishnu-agarwal.blogspot.com/

Tuesday, October 8, 2013

Hack new Yahoo Mail!


Yahoo Mail is back with a Bang! 

By now you must have heard that Yahoo have launched much cooler Mail

However, to make it much usable, I'm trying with few Hacks.

* Increase the Message Read Pane Area (stretch)
In Mailbox vertical split, Inbox area is hardly using 65% of my screen width, and right most ~20% of the area is unused (Ads, Banners!). Moreover, my content viewable area is quite small.
  1. Check if you have Greasemonkey or Tempermonkey installed in your browser.
  2. Install the following script there:
    1. // ==UserScript==
      // @name       Ymail stretch
      // @namespace  http://vishnu-agarwal.blogspot.com/
      // @version    0.1
      // @include    https://in-mg0.mail.yahoo.com/neo*
      // @description  stretches the new YMail Inbox area
      // @match      https://in-mg0.mail.yahoo.com/neo/*
      // @copyright  2012+, You
      // ==/UserScript==
      
      if(ele = document.getElementById('shellcontent')) ele.style.width='1300px';
      

Done!

Will update the post with more tweaks!


References:
1. https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
2. http://vishnu-agarwal.blogspot.com/2010/03/introduction-to-greasemonkey.html
3. http://yahoo.tumblr.com/post/63462971435/yahoo-mails-sweet-16-is-sweet-a-brand-new-view




Thursday, February 7, 2013

Webinar : Selenium Test Automation

Wednesday, Feb 13, 2013 5:00 PM IST

In current era, the software project deliveries are getting very fast paced to meet the strong growing demands from the customers and users esp. on the web application side. The competition is hot and teams which will fail to deliver fast, on time and with high quality will loose out in the race to win the customers and users.  
 
Testing forms a crucial part of the achieving these objectives. Banking just on manual testing may slow the pace and increase the business risk. Hence, there is lot of demand from testing professionals to automate web application testing and hence ensure faster test results and higher test coverage.   

"Selenium automates browsers." That's it

Selenium is one of the most popular tool to achieve this objective.It is widely used due to its robustness and unique features. It does not incur additional cost to company to acquire this tool as it is open source and free and is backed by some of the leading software companies. Those who become skilled in this tool and its technology will gain to stand to grab opportunities coming up in the market place and better their career prospects as software testing professionals.  

Key Learning Areas:  
  • What is Selenium IDE?
  • What is Selenium RC?
  • What is Selenium Grid?
  • What is Selenese?
  • What is Selenium Web Driver?
  • What is Selenium 1.0 vs 2.0?
  • Can we do parallel test execution using Selenium?
  • Why to use Selenium?

Speaker's Biography

Ganesh Sahai has done B. Tech. from IIT Delhi (1993) and EGMP from IIM Lucknow. He has been founder, co-founder and founder team member of few start up companies and initiatives in the field of information technology, marketing and academics.


He has worked for 12 yrs at Adobe since 1999. He has led and setup many of the key testing teams from scratch for various Adobe products, like, Acrobat, Adobe Reader, AIR, CS (Creative Suite) , Tools etc. spanning desktops, handhelds (mob. phones etc.), hosted and enterprise area .


Resources /Reads about Selenium:
Webinar Recording:

Wednesday, January 2, 2013

Hacking Mac : Useful installations & shortcuts

Some of the software usually you'll love to have:


Mac Installers:
  1. iSync (not available for Mountain Loin)
  2. Adobe Reader
  3. Adobe flash player
  4. Adobe Air
  5. Twhirl
  6. Evernote
  7. OneNote
  8. Picasa
  9. Adium
  10. Alfred
  11. Skype
  12. Chrome
  13. VLC
  14. Keepassx
  15. X11 and XQuartz (Macport)
  16. MySQL (mysql/php configuration)
  17. Skitch
  18. Sublime 2
  19. SilverLight
  20. ImageMagick
  21. Ntfs-3G
  22. Java & eclipse
  23. GreaseMonkey / TemperMonkey Script - firefox/chrome
Commands:
  1. Install .dmg from Command Line : hdiutil mount cotvnc-20b4.dmg 
*nix Commands:
In Mac Terminal:

  1. ls -lSr : list files (-S for sort by size)
  2. cd - :  to swap directories to the previous working directory
  3. for f in *.txt;do echo $f;done : Looping over a set of files
  4. find . –name "*.txt" –mtime 5 : files & folders modified in the last 5 days
  5. rename –v 's/foo/bar/g' * : Rename files using regular expressions
  6. mv /path/to/file.{txt,xml} #rename just part of a filename
  7. cp /etc/rc.conf{,-old} #Backup of the file
  8. sudo !! #represent the last command you ran
  9. mkdir my{1,2,3} #will create my1,my2 & my3 folders
  10. Bash Shortcut 
    1. Ctrl + U: Clears the line from the cursor point back to the beginning.
    2. Ctrl + A: Moves the cursor to the beginning of the line.
    3. Ctrl + E: Moves the cursor to the end of the line
    4. Ctrl + R: Allows you to search through the previous commands.
  11. Using Alias : Some useful examples
    1. alias agi='sudo apt-get install'
    2. alias emp='cd /usr/local/mysql/data/employee'
    3. alias grep='grep --color'
    4. alias ls='ls –l' # if you always wanted ls to actually do ls –l


Some shorcuts:
  1. Shift + Command + I : Compose outlook
  2. Shift + Command + N : New Folder
  3. Shift + Command + 4 : Screen Capture
  4. Command + Alt + D : Dock Hide / Unhide
  5. Command + Alt + Esc : Force Quit
  6. Command + M : Minimize
  7. Command + H : Hide 
  8. Command + D : Clone in finder
  9. Command + Q : Quit
  10. Command + I : File Info
  11. Command + S/C/V : Save/Copy/Paste
  12. Command + Delete : Delete
  13. Enter / Return : Rename
  14. Space : Quick Info
  15. Command + Space : Spotlight
  16. Delete : Backspace
  17. Delete + fn : Delete
  18. Command + Z : Undo
  19. Command + Shift + Z : Undo
  20. Command + Left : beginning of line
  21. Command + Left : Ending of line
  22. Alt + arrow : jump by word
  23. Command + Alt + I : Inspector in Browser
  24. Shift + Ctrl + arrow: Word selection
  25. ctrl + arrow : Desktop switch
  26. Lock Screen : Enable Hot Corner

Wednesday, August 29, 2012

BootStrap from Twitter


Twitter BootStrap
What is BootStrap?
It a front-end open source toolkit for rapidly developing web applications. It is a collection of CSS (CSS3) and HTML(HTML5) conventions.
It uses some of the latest browser techniques to provide you with stylish typography, forms, buttons, tables, grids, navigation and everything else you need in a super tiny (only 6k with gzip) resource.

Technologies used in it?
HTML/HTML5, CSS/CSS3, jQuery (but not limited to these J )
  • By nerds, for nerds! Built at Twitter by @mdo and @fat, Bootstrap utilizes LESS CSS, is compiled via Node, and is managed through GitHub to help nerds do awesome stuff on the web.
  • Made for everyone! Bootstrap was made to not only look and behave great in the latest desktop browsers (as well as IE7!), but in tablet and smartphone browsers via responsive CSS as well.
Benefits?
  • A clean and uniform solution to the most common, everyday interface tasks developers come across
  •  Light weight,   Easy & faster development
  • Well tested across OSs & Browsers ( ie6 users please excuse J ) 
I want to try!
·         Site : http://twitter.github.com/bootstrap/
·         Download : http://twitter.github.com/bootstrap/
·         Complete Documents : http://twitter.github.com/bootstrap/scaffolding.html

Note, the above sites/links itself built in bootstrap.

References:

Thursday, May 10, 2012

YUIDoc JavaScript documentation generator released

Today was the official release of the new YUIDoc JavaScript documentation generator. YUIDoc is a Node.js application that generates API documentation from comments in source, using a syntax similar to tools like Javadoc and Doxygen. YUIDoc is currently powering the API documentation for YUI and has been actively updated over the last year.


YUIDoc provides:
  • Live previews YUIDoc includes a standalone doc server, making it trivial to preview your docs as you write.
  • Modern markup YUIDoc’s generated documentation is an attractive, functional web application with real URLs and graceful fallbacks for spiders and other agents that can’t run JavaScript.
  • Wide language support YUIDoc was originally designed for the YUI project, but it is not tied to any particular library or programming language. You can use it with any language that supports /* */ comment blocks.

See the blog post for more details:
http://www.yuiblog.com/blog/2012/05/09/yuidoc-0-3-0-is-official/

Monday, May 7, 2012

Gmail Keyboard Shortcuts


Keyboard shortcuts help you save time by allowing you to never take your hands off the keyboard to use the mouse. You'll need a Standard 101/102-Key or Natural PS/2 Keyboard to use the shortcuts.

To turn these case-sensitive shortcuts on or off:
  1. Click the gear icon in the upper right, then select Settings.
  2. Choose the option next to "Keyboard shortcuts" to turn them on. You can also enable shortcuts automatically by going to http://mail.google.com/mail/?kbd=1

Shortcut Key Definition Action
c Compose Allows you to compose a new message. + c allows you to compose a message in a new window.
/ Search Puts your cursor in the search box.
k Move to newer conversation Opens or moves your cursor to a more recent conversation. You can hit to expand a conversation.
j Move to older conversation Opens or moves your cursor to the next oldest conversation. You can hit to expand a conversation.
n Next message Moves your cursor to the next message. You can hit to expand or collapse a message. (Only applicable in 'Conversation View.')
p Previous message Moves your cursor to the previous message. You can hit to expand or collapse a message. (Only applicable in 'Conversation View.')
o or Open Opens your conversation. Also expands or collapses a message if you are in 'Conversation View.'
u Return to conversation list Refreshes your page and returns you to the inbox, or list of conversations.
e Archive Archive your conversation from any view.
m Mute Archives the conversation, and all future messages skip the Inbox unless sent or cc'd directly to you. Learn more.
x Select conversation Automatically checks and selects a conversation so that you can archive, apply a label, or choose an action from the drop-down menu to apply to that conversation.
s Star a message or conversation Adds or removes a star to a message or conversation. Stars allow you to give a message or conversation a special status.
+ Mark as important Helps Gmail learn what's important to you by marking misclassified messages. (Specific to Priority Inbox)
- Mark as unimportant Helps Gmail learn what's not important to you by marking misclassified messages. (Specific to Priority Inbox)
! Report spam Marks a message as spam and removes it from your conversation list.
r Reply Replies to the message sender. + r allows you to reply to a message in a new window. (Only applicable in 'Conversation View.')
a Reply all Replies to all message recipients. +a allows you to reply to all message recipients in a new window. (Only applicable in 'Conversation View.')
f Forward Forwards a message. + f allows you to forward a message in a new window. (Only applicable in 'Conversation View.')
Escape from input field Removes the cursor from your current input field.
+ sSave draft Saves the current text as a draft when composing a message. Hold the key while pressing s and make sure your cursor is in one of the text fields -- either the composition pane, or any of the To, CC, BCC, or Subject fields -- when using this shortcut.
# Delete Moves the conversation to Trash.
l Label Opens the Labels menu to label a conversation.
v Move to Moves the conversation from the inbox to a different label, Spam or Trash.
+ i Mark as read Marks your message as 'read' and skip to the next message.
+ u Mark as unread Marks your message as 'unread' so you can go back to it later.
[ Archive and previous Removes the current view's label from your conversation and moves to the previous one.
] Archive and next Removes the current view's label from your conversation and moves to the next one.
z Undo Undoes your previous action, if possible (works for actions with an 'undo' link).
+ n Update current conversation Updates your current conversation when there are new messages.
q Move cursor to chat search Moves your cursor directly to the chat search box.
y Remove from Current View* Automatically removes the message or conversation from your current view.
  • From 'Inbox,' 'y' means Archive
  • From 'Starred,' 'y' means Unstar
  • From 'Trash,' 'y' means Move to inbox
  • From any label, 'y' means Remove the label
* 'y' has no effect if you're in 'Spam,' 'Sent,' or 'All Mail.'
. Show more actions Displays the 'More Actions' drop-down menu.
+ Opens options in Chat
  • + moves from edit field in your chat window to select the 'Video and more' menu
  • Next, press to select the emoticon menu
  • Press to open the selected menu
? Show keyboard shortcuts help Displays the keyboard shortcuts help menu within any page you're on. (Note: Typing ? will display the help menu even if you don't have keyboard shortcuts enabled)
k Move up a contactMoves your cursor up in your contact list
jMove down a contactMoves your cursor down in your contact list
o or
OpenOpens the contact with the cursor next to it.
uReturn to contact list viewRefreshes your page and returns you to the contact list.
eRemove from Current GroupRemoves selected contacts from the group currently being displayed.
xSelect contactChecks and selects a contact so that you can change group membership or choose an action from the drop-down menu to apply to the contact.
Escape from input fieldRemoves the cursor from the current input
#DeleteDeletes a contact permanently
lGroup membershipOpens the groups button to group contacts
zUndoReverses your previous action, if possible (works for actions with an 'undo' link)
.Show more actionsOpens the "More actions" drop-down menu.



Combo-keys - Use the following combinations of keys to navigate through Gmail.
Shortcut Key Definition Action
then Send message After composing your message, use this combination to send it automatically. (Supported in Internet Explorer and Firefox, on Windows.)
y then o Archive and next Archives your conversation and moves to the next one.
g then a Go to 'All Mail' Takes you to 'All Mail,' the storage site for all mail you've ever sent or received (and have not deleted).
g then s Go to 'Starred' Takes you to all conversations you have starred.
g then c Go to 'Contacts' Takes you to your Contacts list.
g then d Go to 'Drafts' Takes you to all drafts you have saved.
g then l Go to 'Label' Takes you to the search box with the "label:" operator filled in for you.
g then i Go to 'Inbox' Returns you to the inbox.
g then t Go to 'Sent Mail' Takes you to all mail you've sent.
* then a Select all Selects all mail.
* then n Select none Deselects all mail.
* then r Select read Selects all mail you've read.
* then u Select unread Selects all unread mail.
* then s Select starred Selects all starred mail.
* then t Select unstarred Selects all unstarred mail.

Tuesday, November 22, 2011

Recover deleted file on Linux


If you deleted a file on linux based OS accidentally, and want to recover it, lsof command may help you.

lsof is a Linux tool which can show open files and network connections, and even recover deleted files.

If you have ever deleted a file by mistake; been clearing up log files, or just used rm without thinking, there is a way of recovering that deleted file. For example, to recover a missing access_log used by Apache you can search for it via this command:

$ lsof | grep access_log

which output will be similar to:

httpd 26120 apache 42w REG 253,0 5852 12222531 /apachelogs/access_log (deleted)

The key word to look for here is deleted in brackets. The good news is a process (26120) still has the file open and without this process keeping the file open we would have lost the file permanently. So, with the Apache daemon helping us out we can view the missing info by looking inside the proc filesystem, the process id (26120), and finally in the file descriptor (fd):

$ cat /proc/26120/fd/42

This outputs the contents of my deleted access_log which shows the data is still there. All you need to do now is simply redirect the contents back to /apachelogs/access_log, like this:

$ cat /proc/26120/fd/42 > /apachelogs/access_log

Now you have recovered your access_log with all the data back to its original location. (You should also restart Apache). lsof can do much more, however, this is one example which could save the day.

Feel free to share other useful example of lsof here (in comments).

Tuesday, September 20, 2011

Hacking Firefox : Useful Addons

After using firefox for almost 8 years, I think that there are so many firefox Addons without which my life wouldn't be so comfortable. In the progression of Hacking firefox to make browsing easy, here are few most used Firefox addons:
  • Firebug : Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
  • YSlow : YSlow analyzes web pages and why they're slow based on Predefined & Custom rules for high performance web sites.
  • Pagespeed : Very Similar to YSlow provided by Google.
  • ColorZilla : a color picker, which is used to find any color code just by hovering mouse.
  • Xmarks Sync : is a bookmarking add-on. Keep your bookmarks, passwords and open tabs backed up and synchronized across computers and browsers.
  • FoxClocks : FoxClocks lets you keep an eye on the time around the world - or just your local time - by putting small clocks in your statusbar.
  • AdBlock Plus : Annoyed by adverts? Troubled by tracking? Bothered by banners? Install Adblock Plus now to regain control of the internet and change the way that you view the web.
  • ChatZila : A clean, easy to use and highly extensible Internet Relay Chat (IRC) client.
  • Cookies Manager+ : Cookie manager that allows view, edit and create new cookies. It also allows show extra information about cookies and allows edit multiple cookies at once, as well as backup/restore them.
  • JS Switch : Add a toolbar button or an option in Tool menu to toggle JavaScript.

Friday, August 26, 2011

!(How to Kill PHP Performance)

  1. Wrap sting in single quote instead of double quote As PHP searches variable inside "..." but not in '...'
  2. echo is faster than print print returns valus on success which degrades the performance.
  3. Use echo‘s multiple parameters (or stacked) instead of string concatenation
  4. Use pre-calculations set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x < count($array); $x)
  5. Unset or null your variables to free memory, especially large arrays.
  6. Use require() instead of require_once() where possible
  7. Use full paths in includes and requires less time spent on resolving the OS paths.
  8. Close your database connections when you’re done with them.
  9. Avoid use of @ Error suppression with @ is very slow.
  10. Methods in derived classes run faster than ones defined in the base class.
  11. Use pre-increment over post-increment
  12. Use strict code, avoid suppressing errors, notices and warnings thus resulting in cleaner code and less overheads.
  13. Avoid PHP scripts (unless cached) compilation on the fly every time you call them. Install a PHP caching product (such as APC, memcached or eAccelerator or Turck MMCache) to typically increase performance by 25-100% by removing compile times.
  14. Try to use static pages 
    PHP scripts are be served at 2-10 times slower by Apache httpd than a static page. 
  15. else if statements are faster than select statements aka case/switch.
  16. In OOP, declare a method as static, if it can be . Speed improvement is by a factor of 4.
  17. $row[’id’] is 7 times faster than $row[id], because if you don’t supply quotes it has to guess which index you meant, assuming you didn’t mean a constant.
  18. Use 
    $_SERVER[’REQUEST_TIME’]
    instead of time() or microtime() when script starts
  19. When parsing with XML in PHP try xml2array, which makes use of the PHP XML functions
  20. Use isset where possible in replace of strlen. (ie: if (strlen($foo) < 5) { echo “Foo is too short”; } vs. if (!isset($foo{5})) { echo “Foo is too short”; } ).
  21. Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
  22. Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
  23. Use ip2long() and long2ip() to store IP addresses as integers instead of strings.
  24. When using header(‘Location: ‘.$url); remember to follow it with a die(); as the script continues to run even though the location has changed or avoid using it all together where possible.
  25. Just declaring a global variable without using it in a function slows things down. PHP checks If it exists or now.
  26. Not everything has to be OOP, often it is just overhead, each method and object call consumes a lot of memory.
  27. Make use of the countless predefined functions of PHP, don’t attempt to build your own as the native ones will be far quicker; if you have very time and resource consuming functions, consider writing them as C extensions or modules.
  28. Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview

LinkWithin

Related Posts with Thumbnails