Tag Archive: Programming



Few days back I attended a training given by Alexis Abril. It changed my thoughts about the JavaScript. Earlier my thought on JavaScript was “JavaScript is a scripting language just to manipulate HTML DOM elements mainly”.But after going through in-depth knowledge of JavaScript,I became a fan of JavaScript. It is not only document.getElementById , but it is a real programming language. Its prototype nature is really awesome. No doubts there are some flaws in the language but I think every language contains them. Context,prototype,functions are some of the remarkable features of this language.Moreover Javascript also possesses Object oriented nature but in a slight different manner. Libraries like JQuery,Dojo etc has further extended the capabilities of this language. I would recommend every web developer especially UI developers to learn this language in-depth. Few of the books I am following on the recommendation of Alexis Abril are JavaScript: The Definitive Guide 6th Edition and JavaScript: The Good Parts 1st Edition. I would recommend readers to get the sixth edition of Definitive Guide because it includes HTML5 also. Second book is written by great Douglas Crockford and includes some advance JavaScript philosophies. Pages : Follow flossstuff on Twitter      


Pygame API is an  extension of SDL in python. You can create games quickly and easily  using this. I recently created a repository on github named as ‘Pygame-Examples-For-Learning’ to motivate the learning of this API. This repository consists of various small demos (from hello world to the sprite demo). You can try out those using your own logic and can apply the same into large programs. It also includes a small 3 level game ‘Hungry-Snake’ . Just a contribution from my side to all the enthusiast learners out there (open source too) :) Play with the code to explore more. I will keep updating the repo in future also. You can also contribute in the same. Link to the repo : http://github.com/ankur0890/Pygame-Examples-For-Learning :) Feedback and suggestions are always welcomed :)

Pages : Follow ankurtwi on Twitter      


Sharing data is a very frequent activity in the computer world. There are many great ways and utilities to share data with other people on  network. Python provides a very quick and simple way to share data with people on the network. To share the data within a directory, go to that directory  (through cd command) and execute command python -­m SimpleHTTPServer <portnumber> .Please note that the above command is very case sensitive . Now the entire content under this directory could be accessed on the network by typing http://<ip address of your machine>:<portnumber>  in a web browser. Once your done with the sharing, cancel the data serving by pressing Ctrl + C key combination\. Python comes pre installed in many of the Linux distributions these days. So Linux users just need to run the command simply. As python is cross platform this will work on other platforms too after the installation.

Example : I want to share my music directory . So I will move to my music directory through cd command and type there python -m SimpleHTTPServer 7000 where 7000 is the port number. Then I will tell the ip of my machine to the person with whom I want to share my data. In the browser he types http://<My Ip Address>:<port number>. Screenshots of the same is shown below :

Turn On The Sharing

 

Shared Directory

 

Pages : Follow ankurtwi on Twitter      


This is the next  part i.e part-2  of my article which got published in the International Magazine “Linux For You” also popularly know as LFY. The article was published  under the name of “Let’s Play With Emacs  CLI”  in the August 2010 edition. All the work done is under the creative common license as specified in the widgets also :) If you are new to Emacs and want to learn it ,You must visit the Part-1 first.

Modes in Emacs

The vi/vim editor has two modes: command mode and insertion mode, which you have to switch between based on whether you are inputting text or commands to vi. However, in Emacs, this is not the case; you can run commands by typing a key sequence that’s bound to some function, as we saw above—and while not doing that, you can modify the text in the active buffer.

Emacs’ modes are different; they are editing modes, which extend Emacs’ capabilities, or change the way some features work, when they are invoked. There are several modes available already in Emacs, for editing each of a certain type or class of data, such as:

  • Regular (text) documents
  • Source code in a particular computer programming language (C, FORTRAN, Lisp, etc.)
  • Text formatted in a certain way (outlines, e-mail messages, Usenet articles, character-based illustrations, etc.)
  • Text with mark-up (like Hyper-Text Markup Language, HTML, for example).
  • There’s even a mode for editing non-text (binary) data!

Modes are classified as major or minor. A major mode dictates the main editing behaviour, and is applied only to the active buffer in the current editing session. There can only be one major mode active at a time, though you can switch between different major modes. Minor modes offer some capabilities that are not associated with any particular major mode. Multiple minor modes can be active at a time.We’ll get to some of the available major and minor modes soon, but before that:

How do you find out the currently active mode? Well, remember the Emacs mode-line bar we mentioned earlier, which is just below the buffer? This bar displays (among other information) your currently active modes, in parentheses, toward the right side of the mode line. Below is the screenshot of the same

Mode-Line Displaying Fundamental Major Mode

The major mode that’s active by default (as shown in the above screenshot) is Fundamental mode. The simplest of all Emacs modes, it has the fewest special key bindings and settings. Here, the Tab key is not bound to a function, and works as you’d expect it to (inserts a Tab into the buffer content). (To see some of the functions the Tab key invokes in other modes, search the Key-Index page for “TAB: Completion Commands” and view the next few entries.)

As an example of invoking a minor mode: suppose you want to overwrite text that’s already entered in the buffer—then you want to go into the overwrite minor mode). The function to invoke this is “overwrite-mode”; to activate this minor mode, either press the bound key, “Ins” (Insert), or type Alt+x overwrite-mode. The mode-line bar changes to show the new minor mode, as shown in the screenshot below:

Overwrite Minor Mode As Shown On Mode-Line

Note: Not all minor modes display an indicator on the mode-line; some minor modes are self-evident, such as the Tool Bar mode, which displays the graphical tool bar at the top of the Emacs frame. You can get a description of the mode by typing Ctrl-h m. You will get something like: To get rid of the help window, use Ctrl-x 1.

Important major modes

  1. Fundamental mode (function name: fundamental-mode): Emacs’s default mode with minimal settings and bindings, which we’ve already mentioned.
  2. Text mode (function name: text-mode): a basic mode for text editing.
  3. C mode (function name: c-mode): for editing C programs, a favourite of C programmers.
  4. Wordstar mode (function name: wordstar-mode): this special mode provides you the key-bindings of the old but popular WordStar editor.
  5. Paragraph-Indent Text (function name: paragraph-indent-text-mode): This mode is a special variation of the text mode, where the paragraph-movement commands work for paragraphs whose first lines are indented, and not just for paragraphs separated by blank lines.

Besides these, there are also TeX mode, for editing TeX docs, and lisp-interaction mode, for editing and compiling Lisp code. You can activate any major mode by typing Alt+x followed by the mode’s function name.

Fun with minor modes

As mentioned earlier, minor modes are not restricted to a particular major mode, but can be applied to any major mode. Let’s explore minor modes, with some scenarios to make it interesting.

Scenario 1: If you’re a Java programmer, you have to be familiar with the line System.out.println “text” that’s used to print text to standard output. Tired of typing the same line over and over again?

The solution is a minor mode named Abbrev (function name: abbrev-mode). After you invoke this mode, to assign the abbreviation “sop” for the string “System.out.println”, go to the buffer and type “sop”. Next, type Alt+x inverse-add-global-abbrev. Emacs will ask you to define the expansion for “sop” (screenshot below). Type “System.out.println” and hit Enter. The next time you enter sop in the buffer, it will automatically change it to System.out.println. Finally, it will ask you whether or not to save the defined abbreviation for future sessions.To do away with all the defined abbreviations, use the command Alt+x kill-all-abbrevs.

Defining The Expansion For "sop"

Scenario 2: You want spell-check in the editor

Ispell, an interactive UNIX spelling checker, is built into Emacs, and is a powerful and convenient way to check buffers for misspelled words. To spell-check a word at the cursor, use the ispell-word function, or its key binding, M-$). To spell-check a region, use the ispell-region function. To spell-check a whole buffer, use the ispell-buffer function.

ispell-buffer

Flyspell-mode

Note: ispell gives you a word-by-word spell check . To highlight all the spelling mistakes in the buffer at one time, use the flyspell-mode function.

Scenario 3: You want to automate repetitive invocation of an Emacs command. Suppose you have selected a region that you want to move through 10 spaces. To move it a single space, I’d use Ctrl-x Ctrl-i—but I need to do that 10 times. Hard on the hands and patience!

Emacs provides a way to repeat a command n number of times; in this scenario, I use Ctrl-u 10 Ctrl-x Ctrl-i. This results in the move-region binding being invoked 10 times, doing my job. Ctrl-u is a “universal” binding, and can be used with other key combination to repeated it for a given number of times.

Scenario 4: You want to find a string in the buffer.

Use the various search functions/bindings: isearch-forward will incrementally search the buffer forwards from the cursor. isearch-backward will search backward from the cursor. Ctrl-s or Ctrl-r will show all the matching words in the buffer (performs a non-incremental search)

Well that’s it for my basic introduction to Emacs. I hope you liked it, and found it worth giving Emacs a try. Suggestions and questions are always welcome; feel free to contact me!

Pages : Follow ankurtwi on Twitter      


If you are interested in knowing how an operating system works this book “Operating systems” By “Gary Nutt” is a great source of reading. I just started reading it and already got impressed with the way things are presented in the book. It covers all the topics from system tools to applications tools. Moreover it covers many of the platforms of the present and the past like Unix,Linux,BSD,windows,MacOsX. A must read for all :) I searched the web for ebbok but unable to find it so,I bought it through flipkart. Here’s the link of the same Buy Operating Systems 3rd Ed. from Flipkart.com

I would also like to recommend you guys this great book which not only motivates you but also teaches you important aspects of the Technical world. If you are passionate about Google like me you must read it :D:D Buy The Google Story from Flipkart.com.....

I am reading about Pygame a lot these days. Was looking for a good book and found this one :) It’s simply great :) Buy Game Programming: The L Line 1st Edition from Flipkart.com.

And if you are crazy enough about the design patterns, This book will be your best partner  Design Patterns: Elements Of Reusable Object-Oriented Software....

Pages : Follow ankurtwi on Twitter      

My First Game


I have been working on the pygame API of the python from the past one month and make a small and very basic game “Hungry Snake”. Till now experience with the pygame is superb and currently I am working on the sprite sheets. I made out this game within 2 days and thanks to the online tutorials and python and pygame community for helping me out. Improvements are still required . I am releasing this game under GNU GPL3 license. Its fully open source and if anybody is interested in working with me for further improvements contact me at ankur.aggarwal2390@gmail.com or coolankur2006@gmail.com. You can Download the small game code from http://code.google.com/p/hungry-snakes/downloads/list

Pages : Follow ankurtwi on Twitter      


The v0.0.2 of PyMakeMeLazyNDumb contains :

pygenericroutines.py is a generic python module that comprises of several general purpose routines required most of the times by python automation tools. All the components of PyMakeMeLazyNDumb are based upon it heavily. This module is slightly different in v0.0.2 from v0.0.1 regarding a small fix.

pycreateflswthdr.py is a python app that creates various files having .c, .h, .cpp, .hpp, .java, .py, .pl, .rb, .lua, .php, .sh, .mak, .sql extensions with appropriate commented information headers. Some of the generic fields of the commented info headers are filled automatically. So use this simple but effective app next time when you want to generate files you or others could track later on.  Explanation on – http://richnusgeeks.com/pymakemelazyndumb-an-automation-tool-for-geek-0

 

Pages : Follow ankurtwi on Twitter      

Follow

Get every new post delivered to your Inbox.

Join 70 other followers

%d bloggers like this: