Vintage tutorial : me on batch programing – a 7 year trip on the memory lane

I was searching my gmail for some files – funny enough – one of the results dated back to Dec 6, 2004. Intrigued, I clicked and read – it was one of the tutorials/posts I wrote 7.5 years ago for a site i used to run with an old friend of mine.

It was such a trip down the memory lane back to the teen days ! It was fun to re-read some of the stuff we wrote back then and how cool we thought they are and such….

For the fun of it, since that post still stands and the tutorial can be useful – here it is – a Vintage tutorial I wrote 7.5 years ago on Batch Programming ( I copied/pasted as it is – hold your laughter or else ! )

 

Batch ProgramminG

Batch programming is Super cool, Easy and I classify it as Very Useful.

It is an OS specific language for DOS, it can give you an amazing control over it, this is why it is so Powerful.

Another great thing about Batch is that all you need is a Text Editor, no need for installing anything on your HDD, so you can practically sit anywhere and C0de.

Unlike .exe progs, the source code is always at your disposal, that makes batch programs more flexible: you can edit your prog, add a line or two, save and exit.

There are plenty of other things, like saving time and effort… but remember that

Being OS specific is a bad thing for a programming language, so some people don’t recommend it! And it is not that powerful compared to some other languages, it has limitations… but I think Batch is very easy to learn, it is interesting and useful, and still you can do lot of things with it, you only have to use your imagination, so why not learn it, it won’t take long :P

Note: if you know absolutely nothing about DOS, click here to go to the OS section and read the first 15 lines abut DOS, it is enough; don’t be scared it is not close to Chinese, if you know little about it keep reading…or you can simply copy paste this and see what each one does, learn by test.

First what u need is a text editor; you already have some text editors on your computer like DOS Edit, and Notepad.

To launch Edit all you have to do is go to the run menu or press window+r and type edit then enter

The same goes to notepad, go to run type notepad, or startàall programs à accessoriesà notepad

If you want to ask what about WordPad and Microsoft Word, can I use them?.

The answer is that you can, but you have to do the following, after saving your program you have to edit it to delete all the set of chinese ugly characters.

But I don’t see why you should bother…

So after choosing your editor, you can start typing your commands, one command at a line, and when you save you have to change the extension into .bat instead of .txt

To run your prog all you have to do is double click it in windows mode or type its name at the dos prompt if you are in the right directory.

Now what to type into the batch program:

First let us start by the “hello world!” program.

Rem this is the famous hello world program

Echo hello world!

Save it as .bat and run the prog

If u run in windows mode, you will only see a blink, so run it from the command prompt, you will see the code of your program, and the result, that means Hello world!…

If you want to hide the code written for this command, all u have to do is type @ before your command (@echo hello world!)…

Try it with 2 echos, one with @ and another without it.

Of course you won’t have to type @ at the beginning of each command to hide all your prog, all you have to do is type @ echo off before the commands you want to hide. Remember if you are doing your progs to be executed on other machines and you know that the other machines belong to an intelligent guy; remember to reset the echo by putting @echo on at the end of your prog.

Of course you can echo some other useful stuff other than the hello world, combined with other commands like “if” it can be useful for example to echo the result of a search( found, not found)…

You wanna have more fun with echo, try it with arguments:

@echo off

echo ARGS: %1 %2 %3 %4

echo REV: %4 %3 %2 %1

echo MIXED: %2 %1 %4 %3

type at the prompt: urprog.bat I love rocknroll

oh, I almost forgot, rem stands for reminder, that is if you want to put notes in your programs, very useful when they get complicated

now you can try typing all sort of commands in ur progs, and one click, u execute them all and sit watching the output on the screen

I recommend typing these: :P

@echo off

title watch

@echo off

title watch

ipconfig /all

tree c:\\

netstat -a

netstat -e -s

netstat -r

nbtstat -c

nbtstat -n

 

wow! Did you see it…

well a good advice use the “>” to create or overwrite a file and “>>” to append ( write at the end ) of a file that already exists. Here is an example:

tree /f /a >c:\\mytree.txt

this will provide you a better way for reading the answers now or later( you can add a command to copy or cut the file to floppy drive for example)… use your immagination for what you can do, do not mess with the format command :P

 

 

The IF command

 

It”s easy to find out what it is for. The if command evaluates a condition and, in case of true result, it executes a command. There are three ways to use IF in the following syntaxes:

 

IF [NOT] EXIST file command

IF [NOT] string1==string2 command

IF [NOT] ERRORLEVEL number command

 

Where command is the order (only one) you want to execute. The NOT word is optional, and it makes the condition inverse

You must be thinking, one order, this sucks, just wait a solution will be proposed later.

 

 <span style="text-decoration: underline;">**IF [NOT] EXIST file command.</span>

What it does is to find out if there is or not a file. If the file exist (or not, if the NOT word is typed) then the command is executed. Otherwise, the command is ignored.

Maybe you don”t want to verify a file, but a drive or a directory. In this case, you have to look for the “file” NULL, that is present in any directory. For example, if you want to verify the c:\\folder0 directory, type this:

IF EXIST C:\\folder0\
ULL command

Maybe your command will be to delete it :P

To test if a floppy disk is in, type this:

                IF EXIST A:\<br>ULL command

<span style="text-decoration: underline;"> </span><span style="text-decoration: underline;">**IF [NOT] string1==string2 command</span>

Compares the two strings: string1 and string2.

In case that every character is equal in both (case sensitive and blank spaces ignored), the command is executed.

 <span style="text-decoration: underline;">**IF [NOT] ERRORLEVEL number command</span>

This evaluates the last error level number present. Error levels are generated by programs to inform about the way they finished their execution. For example, format returns error level 3 when is Ctrl-C is pressed, and error level 0 when it finish normally. Not all the programs return error levels, and error levels are lost when another program is runned.

This is the most useful feature of IF command. We”ll explain it later, with the CHOICE command.

 

<strong><span style="text-decoration: underline;">Labels and GOTO command.</span></strong>

Labels are used to identify a line of the batch file. The way to put a label inside .bat progam is simply to put : before the label name.

For example, to create the “example” label, do this:

                :example

And that”s all.

Labels are really useful when combined with GOTO.

GOTO simply goes to the labeled line you want.

For example, to go to the :example label just type:

                GOTO :example

That makes the execution of the .bat file continue at that line, no matter if it was far below the current line or before it.

A good example of the GOTO command is this

@echo off

:a

net send pcname hi

goto :a

That will create an interminable loop, and will keep sending the message hi to ur friend over and over again(don’t do it, this is not nice)

To stop your program, you have to press ctrl+c

To understand yourself labels, try the net send prog with 2 messages, like hi and how are you, watch what happens!

 

You can type at the end of your prog :end, and whenever you want to finish the execution of the prog just type :end

 

Do you remember that in the IF you can only put one order, But now, you can create a label and make this only one command be GOTO :label. Then, in this :label you can have as many commands as you want, and finish the execution or return to the program point you wanted with :end or :new_label

The command FOR

Now we”ll se how to make a batch file smaller. The for order is not very useful, but sometimes is exactly what you need. So lets see it.

The FOR command makes a “variable” change it”s value between the possibilities you gave it, and executes a command every time it changes. The

syntax is that:

                FOR %%A IN (list of values) DO command

Here %%A is the name of the variable. (list of values) is just the list of values (easy, uh?) between which will change the variable %%A. The different values are separed by a blank space, and are only considered as strings.

To understand it, type this :

FOR %%B IN (www. Xim. uni.cc ) DO ECHO %%B

This will make the variable %%B change it”s value. First time will be www. Second time Xim. , and third uni.cc . Every time the %%B value is changed, the command after the DO word (ECHO %%B in our example) is executed.

So this line in a batch file will print in our screns:

                www.

                Xim.

                uni.cc

There are other stuff to cover, there”s still choice, call, shift, and pause aka the real important stuff but I guess that will have to wait for a second tutorial Read More

Online security is a myth – yet here are 4 useful tips

Online security is almost a myth but what you can do is make it really hard for someone to hack your account or at least catch them while doing so.

Below are some security tips that don’t include “choose a hard password” – “don’t use an easy password like your name or phone number” and so on – I am pretty sure that almost everybody has heard those tips and yet fails to apply them.

Tip 1 : Securing you email

Most of your accounts, blogs, online transactions, chat logs, contacts, “forget my password” forms end up in your email… so it is really basic to take extra measures to secure your account.

The good news is that hacking Gmail/Hotmail is not that easy anymore – hackers have to rely on hacking “you” – they usually do so by guessing your password, installing a software on your computer that saves the keys you type, including your password or by sending you fake online login form (phishing), viewing your saved passwords in your browser and so on.

Some common sense applied and you will not be victim of those attacks, but since this is a security tutorial, it is a must to assume that at some point, your password is compromised so you must :

a.       Make sure you can recover/prove you identity and recover your password

b.      Add a second layer of security

Here are some step by step instructions on how to do on your gmail account ( It will be too much doing the same tutorial for all the email providers, it is the same logic, just different screens, I  believe many people are using gmail anyhow )

go to  https://www.google.com/accounts/ManageAccount

You will find a nice screen – on the top , there is the security settings

 

The first thing to do is have your password recovery procedure covered. You can set a secondary email, specify a security question or you can specify your phone number and a SMS will be sent to you (It is bit creepy to tell google you phone number – but sometimes you have to choose the lesser evil )

 

Step 2 : assuming things got worse and your account was compromised. You can add a second layer of security – this is called “two factor authentication” – it relies on – surprise – 2 factors :

a – that you know your username/password.

b – it relies on your ownership of something physical – in this case your cell phone
The username and password part is easy and it was covered how to protect them, now here is how you can bring in your phone to the equation.

After entering your password, a verification code is sent to your mobile phone via SMS, voice calls, or generated on an application you can install on your Android, BlackBerry or iPhone device. This makes it much more likely that you’re the only one accessing your data: even if someone has stolen your password, they’ll need more than that to access your account. You can also indicate when you’re using a computer you trust and don’t want to be asked for a verification code from that machine in the future ( ease of use )

 

Now that you have updated your account with a secure password, built a recovery procedure and have a second layer of authentication that can work in the background – you are probably more secure.
However those are additional steps you can take to make sure no one has access to your account :

1- check what apps/3rd parties have access to your account : with OpenID, some applications use your already existing gmail/hotmail/twitter/facebook account to login to the site. While they don’t have access to your password, they may have reading/writing abilities to your account – you can check this in your gmail by visiting https://www.google.com/accounts/IssuedAuthSubTokens?hl=en
Revoke access to site that you don’t use anymore.

2- from time to time, check who accessed your gmail account and from where , to do so, scroll to the bottom of the page in gmail , click details :

You will be able to view a list of the IPs/Countries that accessed your account – if anything is suspicious, you can “log out” all the other people who are signed in and needless to say, change your password

 

if you click “sign out all other session” – everyone logged in will be signed out – you can also set an alert for “unusual

3- check your autoforwarders list and mail rules : https://mail.google.com/mail/?shva=1#settings/fwdandpop
the first thing a smart hacker would do, is not changing your password, but adding an auto-forwarder so they can read your mail and collect more data about you. So check there are no forwarders and rules you are not aware of.

4 – don’t leave out your phone unlocked – hanging around with access to your email

5 – Never use your company mail for personal stuff : IT people have a access to the mail server and can read out your emails, many mail servers that belong to a company are also silently aggregated. Also emails exchanged using your company address are not your property.

 

Tip 2 : figuring out / investigating the people you are with

Sometimes personal trust is all you have to communicate and willingly share details. Building this trust is a human process that usually comes after endless hours of chat and facebooking and blog reading.
However there are some basic steps you can  take to verify the online identity of someone.

1 – find them on social networks : they must have a blog, they must be subscribed to linked in, they must have posted somewhere on a forum etc…  and ultimately – you could ask them to video chat , have a skype voice call etc… not finding anything on them is “fishy” enough for you not to trust them …. (trust is a 2 way process, so don’t share details if they are not)

 

2- Verify their websites/blog : if you are dealing with a blogger, chances are that they have a .com /.info / .net (domain name ) – if they do, you can check out to whom this belongs.

You can do so using whois.net

Here is an example of the info of “who is behind” nasawiya http://www.whois.net/whois/nasawiya.org

 

this info is used to process credit card transaction to buy the domain name and is highly accurate. ;)

 

 

Some people however, but not everyone, protects this info by paying to the hosting company an extra fee, here is for example sawtalneswa site info http://www.whois.net/whois/sawtalniswa.com
it pretty much tells nothing ;p

If someone protected their info, you can always wonder and ask why they did so

Tip 3 : https everywhere

there is a nasty little firefox extension called https everywhere, this little thing will encrypt all your browsing traffic whenever possible, making it impossible for people to intercept this traffic and hack into it.
You can install https and read about it from here http://www.eff.org/https-everywhere

Tip 4 : stay tuned to security news

in the security world, there is always endless updates – the way to stay protected is to stay updated on what is going around – for activists i’d recommend to subscribe to Electronic Frontier Foundation Newsletter – it is reffered to as “the first line of defense” and it earned this reputation.
They have pretty nice newsletter to keep you posted somehow on the tech and security world ( it is not a pure newsletter ) – also the EFF have some pretty nice logos and their web address is pretty short and easy to remember https://www.eff.org

Read More

on stupid brain theories

One of the most common “sexist” remarks/jokes/excuses i always hear is:

“Women have smaller brain; meaning, men are superior”

Some use it as an indisputable argument (hey, it is science!), others derive endless jokes about it that even include “3a2l l mara azgar min 3a2l l djejeh” and so on…

The sad part is that anyone making this “smart” statement has probably not opened a science magazine for the last 20 000 year.

If they did, they would have read somewhere that for the last 20 000 year, as humans got exponentially smarter, the human brain has been getting smaller.

To whom do we owe this “discovery”?

John Hawks, a researcher in anthropology (do not confuse him with the anthropology dude in the Bacardi ad)

In Sept 2010, John Hawks was in the middle of explaining his research on human evolution when he dropped a bombshell. Running down a list of changes that have occurred in our skeleton and skull since the Stone Age, the University of Wisconsin anthropologist nonchalantly adds, “And it’s also clear the brain has been shrinking. This happened in China, Europe, Africa—everywhere we look.”

So wait! Let’s get this straight…

Studies show that as humans were getting smarter, their brain was getting smaller. Meaning that a smaller brain does not mean dumber/inferior person! Woohaa! Women are not inferior? they could be even ahead on the evolution path? and since evolution doesn’t happen overngiht are they 200 000 years ahead? ;p (sarcasm)

Now, putting sarcasm off, here are some theories and facts:

  • As the brain shrinks, its wiring becomes more efficient, transforming us into quicker, more agile thinkers while a bigger brain is bulkier and slower.
  • Christopher Stringer, a paleoanthropologist and expert on human origins at the Natural History Museum in London says:
    “As a general rule, the more meat on your bones, the more brain you need to control massive muscle blocks.”
    For example: The Homo sapiens, who had the biggest brains, lived 20,000 to 30,000 years ago in Europe. Called the Cro-Magnons, they had barrel chests and huge, jutting jaws with enormous teeth. Consequently, their large brains have often been attributed to brawniness rather than brilliance.
  • The brain organ is also known to be such a glutton for fuel, it gobbles up 20 percent of all the calories we consume. So it takes a higher amount of energy to build a bigger brain and more energy to maintain it. In terms of survival this is really bad and in other words natural selection and evolution is favoring female bodies and brains. (Less energy cost for a more effective and smarter brain – the resemblance to smaller more effective CPUs or “computer brain” is striking)

So here is again, another proof that brain size theories are stupid and honestly, I am a bit weary of those, I just read that now women are smarter then men cuz their gray matter or was it their white matter? is bigger.

So colors and sizes and shapes aside – please, if you have a brain theory, please do not share it ;p and there should be a philosophical principle of never using science to determine our discrimination patterns (6).

Read More

Meet the Geeks : 25 faces (and wiki links) of famous geeks through history

You’ve heard of things they built and invented or studied their name at school. They probably established the biggest tech companies affecting our lives today but you may not have seen the faces and met the people.
So meet the geeks !



Alan Turing : English mathematician, logician and cryptographer. Turing is often considered to be the father of modern computer science. http://en.wikipedia.org/wiki/Alan_Turing



William Hewlett the co-founder, with David Packard, of the Hewlett-Packard Company (HP). http://en.wikipedia.org/wiki/William_Hewlett

 


David Packard co-founder of Hewlett-Packard (1939), serving as president (1947-1964), CEO (1964-1968), and Chairman of the Board (1964-1968, 1972-1993). He served as U.S. Deputy Secretary of Defense from 1969-1971 during the Nixon administration. Packard was the recipient of the Presidential Medal of Freedom in 1988 and is noted for many technological innovations and philanthropic endeavors. http://en.wikipedia.org/wiki/David_Packard



Thomas Watson was the American president of International Business Machines (IBM), who oversaw that company’s growth into an international force from the 1920s to the 1950s. Watson developed IBM’s effective management style and turned it into one of the most effective selling organizations yet seen, based largely around punched card tabulating machines. A leading self-made industrialist, he was one of the richest men of his time and was called the world’s greatest salesman when he died in 1956. http://en.wikipedia.org/wiki/Thomas_J._Watson



Edgar Codd invented the relational model for database management, the theoretical basis for relational databases. a very influential general theory of data management http://en.wikipedia.org/wiki/Edgar_F._Codd



Dennis Richie and Ken Thompson
The Guys basically responsible together for Creating C Programming Language (among the great things they did )

Ken Thompson American pioneer of computer science notable for his work with the B programming language and his shepherding the Unix and Plan 9 operating systems. http://en.wikipedia.org/wiki/Ken_Thompson

Dennis MacAlistair Ritchie (born September 9, 1941) is an American computer scientist notable for his influence on C and other programming languages, and on operating systems such as Multics and Unix. He received the Turing Award in 1983 and the National Medal of Technology in 1998. Ritchie was the head of Lucent Technologies System Software Research Department when he retired in 2007. http://en.wikipedia.org/wiki/Dennis_Ritchie



Richard Stallman an American software freedom activist and computer programmer. In September 1983, he launched the GNU Project to create a free Unix-like operating system, and has been the project’s lead architect and organizer. With the launch of the GNU Project, he initiated the free software movement; in October 1985 he founded the Free Software Foundation.
http://en.wikipedia.org/wiki/Richard_stallman



Linus Torvalds a Finnish software engineer and hacker, best known for having initiated the development of the Linux kernel. He later became the chief architect of the Linux kernel, and now acts as the project’s coordinator. He also created the revision control system Git. http://en.wikipedia.org/wiki/Linus_Torvalds



Alan Cox a British computer programmer heavily involved in the development of the Linux kernel since its early days 1991. http://en.wikipedia.org/wiki/Alan_Cox



Grady Booch Part of the Trio [Three Amigos] who came up with UML :)  the others are  James Rumbaugh and Ivar Jacobson http://en.wikipedia.org/wiki/Grady_Booch



Ivar Jacobson Part of the Trio [Three Amigos] who came up with UML :) the others are : James Rumbaugh and Grady Booch http://en.wikipedia.org/wiki/Ivar_Jacobson

 



Steve Wozniak Stephen Gary “Woz” Wozniak (born August 11, 1950 in San José, California) is an American computer engineer, and the co-founder of Apple Computer (now Apple Inc.), with Steve Jobs. His inventions and machines are credited with contributing greatly to the personal computer revolution of the 1970s. Wozniak created the Apple I and Apple II computers in the mid-1970s. The Apple II gained a sizable amount of popularity, eventually becoming one of the best selling personal computers of the 1970s and early 1980s. Wozniak has several nicknames, including “The Woz”, “Wonderful Wizard of Woz” and “iWoz” (a reference to the ubiquitous naming scheme for Apple products). http://en.wikipedia.org/wiki/Steve_Wozniak



Steve Jobs an American business magnate and inventor. He is the co-founder and chief executive officer of Apple Inc. Jobs also previously served as chief executive of Pixar Animation Studios; he became a member of the board of directors of The Walt Disney Company in 2006, following the acquisition of Pixar by Disneyhttp://en.wikipedia.org/wiki/Steve_Jobs



Bill Gates an American business magnate, philanthropist, author, and is chairman of Microsoft, the software company he founded with Paul Allen http://en.wikipedia.org/wiki/Bill_Gates



Paul Gardner Allen (born January 21, 1953) is an American investor and philanthropist who co-founded Microsoft with Bill Gates and is one of the wealthiest people in the world. He convinced Gates to drop out of Harvard University in order to create Microsoft.



Larry Page an American entrepreneur who co-founded the Google web search engine, now Google Inc., with Sergey Brin http://en.wikipedia.org/wiki/Larry_Page



Sergey Brin a Soviet-born American entrepreneur who co-founded Google with Larry Page. http://en.wikipedia.org/wiki/Sergey_Brin


Mark Elliot Zuckerberg an American computer programmer and Internet entrepreneur. He is best known for creating the social networking site Facebook, of which he is chief executive and president. It was co-founded as a private company in 2004 by Zuckerberg and classmates Dustin Moskovitz, Eduardo Saverin, and Chris Hughes while they were students at Harvard University http://en.wikipedia.org/wiki/Mark_Zuckerberg




Jack Dorsey, Biz Stone and Evan Williams co-founded Obvious which then spun off Twitter, Inc



Kevin Mitnick is a computer security consultant, author, and former computer hacker. In the late 20th century, he was convicted of various computer- and communications-related crimes. At the time of his arrest, he was the most-wanted computer criminal in the United States http://en.wikipedia.org/wiki/Kevin_Mitnick



Joel Spolsky Avram Joel Spolsky (born 1965) is a software engineer and writer. He is the author of Joel on Software, a blog on software development. He was a Program Manager on the Microsoft Excel team between 1991 and 1994. He later founded Fog Creek Software in 2000 and launched the Joel on Software blog. In 2008 he launched the now successful Stack Overflow programmer Q&A site in collaboration with Jeff Atwood. Using the Stack Exchange software product which powers Stack Overflow, The Stack Exchange Network now hosts over 50 Q&A sites. http://en.wikipedia.org/wiki/Joel_Spolsky



Jimmy Wales an American Internet entrepreneur and a co-founder and promoter of the online encyclopedia Wikipedia http://en.wikipedia.org/wiki/Jimmy_Wales



Jeff Attwood Jeff Atwood is a software developer, book author, podcaster and writer of the popular blog Coding Horror. Together with Joel Spolsky, he founded the question-and-answer website network Stack Exchange http://en.wikipedia.org/wiki/Jeff_Atwood


David S. nMiller an American developer working on the Linux kernel, where he is the primary maintainer of networking and the SPARC implementation, and is also involved in other development work. He is also an active member of the GNU Compiler Collection steering committee. http://en.wikipedia.org/wiki/David_S._Miller




Randall Patrick Munroe is an American webcomic author and former NASA roboticist as well as a programmer, best known as the creator of the webcomic xkcd.

Read More

roads

 

 

 

 

I love roads
Roads take us away or bring us back
the longer the road the stronger is the yearning
the longer the road the more liberating is the get away

adventure, surprises, discovery
Roads take us anywhere

but we hate roads now
we are too lazy to take them
or in too much hurry to enjoy them
we’ve built too many highways
and too many fast cars

our roads didn’t used to be like that
they didn’t cut through the land and injure it
a road moved with the land, it rose, it fell, it curved.

People didn’t drive on a road to make great time.
They drove on it to have a great time.

Please remember, Roads are for life

https://www.facebook.com/RoadsForLife

Read More