This is the P2PU Archive. If you want the current site, go to www.p2pu.org!
The revisions let you track differences between multiple versions of a post.
hemanth Hello Hackers :)
SourRust> hey
hobs> hey there
hobs> sorry im late!
lakshmi> hi
manth is very happy to see people logging in exactly on time :)
SourRust> :P
hemanth> (:
hemanth> So, did anyone try limpid ?
adam_collado> hey there :)
hobs> yep
adam_collado> using it right now
hobs> just starting it up
hemanth> I made a ubuntu package lately, will share later
hemanth> now, if all are set, lets start with todays class
hobs_limp> sounds good hemanth
hemanth has changed the topic to: Conditionals Execution.
hemanth> Conditions we have many in life...
hemanth> If i have $$ i will buy this or else i will buy that
hemanth> To make this class very interesting http://www.youtube.com/watch?v=txwsVSOw_8M
hemanth> i just want you all to see this video
hemanth> :)
hobs_limp> cool hemanth
hemanth> we will learn Conditionals Execution from this video
jmuniz> How much money do you have? haha...
hobs_limp good example of a conditional lol
manth this is a fun way of learning, no offense
hemanth> ok so, how could the responses be
hobs_limp no offense taken
lakshmi> :)
hemanth> if you have x amount of money
hemanth> and x > 1000000, i will marry you
hemanth> else i will not marry you
hemanth> or it can be
hobs_limp haha
hemanth> while your money is greater than 100000 i will be married
hemanth> until your money is greater than 100000 i will be married to you
hemanth> or be married till money is greater than certain value
hemanth> these are conditions, based on which the action is decided
hemanth> same way in programming, there are few conditions we write to decided what to do based on the data
hemanth has changed the topic to: BASH Conditionals Execution
hemanth> At any point if you have any doubts just o/
hobs_limp>21 I will hemanth
hobs_limp its clear so far
jmuniz> got it
hemanth> The first construct is the 'if-else model'
hemanth> i hope u are all ready with your terminals
hemanth> the generic syntax of if-else model is
hemanth> if test-commands; then
hemanth> consequent-commands;
hemanth> [else alternate-consequents;]
hemanth> fi
edguy> hi, sorry for being late
hemanth> redguy, no issues
hobs_limp a thousand lashes
hemanth> so you must notice that its like a block
hemanth> starts with if
hemanth> end with fi
hemanth> with else in between
hemanth> if test-commands; then
hemanth> consequent-commands; [elif more-test-commands; then more-consequents;] [else alternate-consequents;] fi
CSSDevMonkey> hey guys
hobs_limp hey dev monkey
hemanth> is it clear, or is the text messed up?
hobs_limp>21 do you have to putt the else/elif in brackets hemanth?
hobs_limp or is that to show they are optional
hemanth> optional
hobs_limp cool
hemanth> will get to know, as we will see the examples now
manth shared logs so far with CSSDevMonkey and redguy
hemanth> in your terminals now
hemanth> type in a simple if else structure
hemanth> money=100
hemanth> if [[ $money > 100 ]] ; then
hemanth> echo You have more than 100
hemanth> else
hemanth> echo You have less than or equal to hundred
hemanth> fi
hemanth> Done?
adam_collado> yep
hobs_limp yep
edguy> why [[ and not [ ?
adam_collado> printed out the latter case, because money=100, and hence, is less or equal too 100
SourRust> done now
jmuniz> hold on, I mistyped the last fi...
hemanth> redguy, good question
hemanth> [[ is a bash keyword similar to (but more powerful than) the [ command
hemanth> Unless you're writing for POSIX sh, [[ is recommend
edguy> oh, so it doesnt use /usr/bin/test ?
hemanth> [ ("test" command) and [[ ("new test" command) are used to evaluate expressions
hemanth> this is the latest and the greatest practices of BASH
hemanth> redguy, test can also be used
hemanth> In almost all shells (the oldest Bourne shells are the exception), [ is a synonym for test
hobs_limp sweetness
hemanth> clear?
hobs_limp it just is a more full featured test comparison operator, got it
jmuniz> ok
hemanth> the if [[ arg1 OP arg2 ]] for Arithmetic tests.OP is one of -eq, -ne,-lt, -le, -gt, or -ge.
edguy> clear, thanks
hemanth> that is =,!=,<,>,>= for strings, can be used either way
hemanth> redguy, no issues, [ ] will bomb on the variable is "" and if not quoted
jmuniz> ah!
hemanth> yes, you can try that :)
hemanth> so, anymore o/ ?
hobs_limp hey
hobs_limp not from here
hemanth> if [[ $money > 100 ]] ; then
hemanth> echo You have more than 100
hemanth> elif [[ $money -eq 100 ]] # -eq also
hemanth> echo You have exactly 100
hemanth> else
hemanth> Not bad
hemanth> fi
hemanth> Note: its elif, not *elseif*
hemanth> done?
hobs_limp easy mistake to make hehe
hemanth> echo is everything fine :) ?
hemanth> Now, lets see the case command
hemanth> case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
hemanth> ^ in the generic syntax
hemanth> Execute commands based on pattern matching.
hemanth> Selectively execute COMMANDS based upon WORD matching PATTERN.
hemanth> The '|' (pipe) is used to separate multiple patterns.
hemanth> lets try this one
hobs_limp great!
hemanth> read -p "Enter the name of an animal name : " animal
hemanth> #the above is used to read the data entered by the user to an variable called animal
hemanth> echo -n "The $ANIMAL has "
PaBLoX> Hi!
hemanth> echo -n "The $animal has "
PaBLoX> Sorry for being so late U_u
hemanth> PaBLoX, its ok, i will share the logs
hemanth> horse | cow | cat) echo -n "four";;
PaBLoX> I'm in limpid btw
hemanth> man|woman) echo -n "two ";;
hemanth> PaBLoX, kool :)
hobs_limp me too!
hobs_limp we did it
hemanth> *) echo -n "an unknown number of legs!";;
hemanth> # * is the default case, that is in case of no match
hemanth> esac
hemanth> done? Notice the case starts with case and ends with easc with patterns to match
jmuniz> could you reformat... it broke up for me
jmuniz> retype
edguy> \o: can the patterns contain wildcards?
hemanth> redguy, yes :)
hemanth> redguy, like *.mp3
hobs_limp \o wouldnt you want it to be unknown and then end with number of legs?
hemanth> jmuniz, which part?
hobs_limp appended to the end?
hobs_limp let me run it first
hemanth> ok!
jmuniz> then all of them would go to "unknown ?
jmuniz> just the part after "animal has.."
jmuniz> the cases
hemanth> jmuniz, no it's based on your input
hemanth> * is the default case, that is in case of no match
jmuniz> ok
hemanth> *) means, if all fail the control goes there
jmuniz> Ah! I see
hemanth> Okies, now lets move on, or are there any other o/
hobs_limp>21 hemanth
hemanth> yes
jonsul> I made it :D
hobs_limp my question is less programming related but more logic related, wouldnt it say "Enter an animals name" man "two"
hobs_limp the animal has two
hobs_limp sorry
hobs_limp also this doesnt run for me but I didnt write case or esac in it
hobs_limp I think I might have missed a piece of code one second let me hunt for it
hemanth> yup, echo legs after the esac ;)
hemanth> or add it there itself
jonsul> o/ am I late? I thought it was 11:30 or something?
hemanth> jonsul, UTC 15:30
hobs_limp>21 hemanth: where is the word case, sorry
jonsul> sorry, that's my time^^
hemanth> jonsul, its ok
jmuniz> I think I missed that "case" as well...
jmuniz> haha
hemanth> Ok, i will give u the block again
hobs_limp> thanks hemanth
jmuniz> thank you
hemanth> read -p "Enter an animal name:"
hemanth> read -p "Enter an animal name:" animal
hemanth> # ignore the first line
hemanth> case $animal in
hemanth> horse|cow|cat) echo "Has 4 legs" ;;
hobs_limp now it works fine!
hemanth> man|hen) echo "Has 2 legs" ;;
hemanth> *) echo "Sorry i'm still counting" ;;
hemanth> esac
hemanth> clear?
edguy> yup
hemanth> ok now, select : select name [in words ...]; do commands; done
hemanth> as redguy mentioned about wildcards, lets see one now
hemanth> select flie in *;
hemanth> do
jonsul> o/ sry to interupt, will we be covering functions today? I'm still catching up with the last log
hobs_limp we are doing conditionals right now
CSSDevMonkey> i'm writing exactly what you are, and it keeps breaking for me
hemanth> jonsul, we have conditional execution of the remaining languages also to do!
CSSDevMonkey> i have to be missing something
jonsul> okay cool
manth calls volunteers to make notes :)
hobs_limp I will pastebin
hemanth> hobs_limp, better use etherpad
hobs_limp ill use etherpad!
jonsul> http://tille.garrels.be/training/bash/ch07.html <= nice tutorial/reference on conditionals
hobs_limp http://piratepad.net/kl4AF3W1O7
hemanth> okies, no getting back to select
hemanth> hobs, http://pad.p2pu.org/
hemanth> hobs, later on lets update
hobs_limp yes
hobs_limp keep going I will move it
hemanth> hobs, now i will stick to ur link
hemanth> jonsul, thanks for the sharing the link, later one we will be make once such wiki
CSSDevMonkey> i got it working, i went and did it again
hemanth> CSSDevMonkey, ok :)
hemanth> So all are in http://piratepad.net/kl4AF3W1O7 i blv
PaBLoX> btw, I think http://ethercodes.com/ it's suits better our needs! ;)
jmuniz> Sweet! I missed the "case" and now it works fine
hemanth> PaBLoX, yup i had mentioned that in the forum thread of p2pu :)
hobs_limp it doesnt have bash :(
hemanth> PaBLoX, the issue is ethercodes server it pretty flaky
PaBLoX> oh,
PaBLoX> okay :)
hemanth> Ok, now did u all try select example?
hemanth> redguy, you can see * RE been used here
hemanth> hit Ctrl^C to break
jmuniz> \oI'm getting a list of my home directory
hemanth> yup
hobs_limp thats pretty nice
hemanth> select any one of them, like type 1 and hit enter
jmuniz> \o is fname a special varible?
hobs_limp so select is like a little choosing program built in
hemanth> jmuniz, no
jmuniz> or is the * selecting everything
hemanth> jmuniz, its just a variable
jmuniz> Ah! I think I got it
hemanth> just say echo *
hemanth> in another terminal
hemanth> echo *
jmuniz> Yes!
manth is been renamed as schdmidt in the pad!
hemanth> strange!
hobs_limp someone was named jingle heimer so I took the liberty
hemanth> okies now moving on
hobs_limp its not the server
hobs_limp>21 sorry hemanth
hobs_limp just a little fun
jmuniz> haha
hobs_limp its a child's song here
jonsul> fun is always good^^
hemanth> hobs_limp, i was suspecting its would be you ;)
hobs_limp im a trickster
jonsul> and I helped :D
hemanth> as you can a see i have added few data there in the pad
hemanth> (( )) and [[ ]] and && and ||
hobs_limp yep
hemanth> lets see how they work
lakshmi> yes
jmuniz> \o is the 0 or 1 like True and False?
hemanth> yes 0 is always true
hemanth> 1 is false in bash
jmuniz> got it
hobs_limp thats why successful programs return 0
hobs_limp>21 right hemanth
jonsul> wow! that's odd
hemanth> mkdir d && cd d ; pwd
jmuniz> got it
hobs_limp so you use a conditional to actually just do two things, that makes sense
jonsul> compared to other languages bash is a bit like pig latin :/
hobs_limp it does have its mixups sometimes
hemanth> && => and operator
hemanth> 0 && 1 -> 0
hemanth> 1 && 1 -> 1
jonsul> I'm gonna have to get used to that
hemanth> now
PaBLoX> (Somebody has to copy the contents then to the pad.p2pu.org)
hemanth> [[ -f test.txt ]] || echo file test.txt not found
hemanth> touch file.txt
hemanth> [[ -f test.txt ]] || echo file test.txt
hemanth> [[ -f test.txt ]] && echo file test.txt found || echo file test.txt
hemanth> PaBLoX, yes we will re-factor that
PaBLoX>21 hemanth: ok ;)
hemanth> clear? any o/
hobs_limp I am copying all that he puts in the current etherpad
hobs_limp>21 makes sense hemanth, that seems useful for a lot of stuff
hobs_limp check to see if a config gile exists and if it does read it for my programs settings
PaBLoX> o/
hemanth> PaBLoX, yes
PaBLoX> I don't know if you already say it, but it's important/interesting to note the the [[ -f asd ]]
PaBLoX> is a short way to write the test command
PaBLoX> test -f asd
jonsul> o/ last interrupt, have I missed any assignments yet?
hobs_limp yep sorry PaBLoX we went over that a little bit
hobs_limp [[]] being the superior tester
PaBLoX> hobs_limp: nice ;)
PaBLoX> let's continue then.
hobs_limp gud
hemanth> PaBLoX, yes that was said b4 in the class
hemanth> x=100 ; ! [[ $x >100 ]] && echo yes || echo no
hobs_limp no
hobs_limp I predict this outcome
hemanth> ! => not/negation that is if the condition turns out to be false its negated to true and vise versa
jmuniz> \o is this case sensitive?
hemanth> jmuniz, yes very much!
jmuniz> cool
jmuniz> ls
hemanth> hobs_limp, try it ;)
hemanth> jmuniz, ls ;) ?
jmuniz> haha... wrong window.
hobs_limp I was wrong!
hemanth> hobs_limp,:)
hemanth> okies, if allz fine, lets move on...
hemanth> o/ ??
hobs_limp yeah makes sense, echo yes will always evaluate to true
hobs_limp hehe
hemanth> okies nice
hemanth has changed the topic to: PYTHON Conditional execution
hemanth> All of switch over to python
hobs_limp roger
hemanth> control flow constructs. Specifically: and and or
hemanth> if the left argument to and evaluates to False, the right argument doesn't get evaluated at all
hemanth> if the left argument to or evaluates to True, the right argument doesn't get evaluated at all
hemanth> lets see examples
hemanth> >>> 'a' and 'b'
jonsul> I used to do python, let me know if I'm rusty::: for x in y: if x > 2: print(x)
hemanth> jonsul, good, np, but lets move from grass root level, that would help the fresh(wo)men
jmuniz> b
hemanth> >>> '' and 'b'
jonsul> k sry
hemanth> >>> 'a' and 'b' and 'c'
hemanth> what are the o/p's?
lakshmi> 'b' syntax error 'c'
hobs_limp well 'a' and 'b' is 'b'
hobs_limp and 'a' and 'b' and 'c' is c
hobs_limp 'c'
hemanth> lakshmi, be careful while you copy paste
hobs_limp so right most side
hemanth> lakshmi, a single space also matter!
hobs_limp '' and 'b' is '' because '' is nothing I think
hemanth> kool, no moving on
lakshmi> yes
lakshmi> thanks
hemanth> >>> 'a' or 'b'
jmuniz> k
hemanth> >>> '' or 'b'
hemanth> >>> '' or [] or {}
hobs_limp do sequences have precedence?
hobs_limp it returned {}
jmuniz> {}
hobs_limp can nulls have precedence
hemanth> if all are false, what will happen?
hobs_limp left hand side
hobs_limp oh wait
hobs_limp right hand side
hobs_limp ok
hemanth> :)
hobs_limp that makes more sense!
hemanth> >>> a = "first"
hemanth> >>> b = "second"
hemanth> >>> 1 and a or b
hemanth> >>> 0 and a or b
jonsul> is that a question?
hemanth> yup :)
hobs_limp I put them in
hemanth> what did u notice?
hobs_limp its first
hobs_limp second
hobs_limp in order
jonsul> 1 the first time because 1 is always rue
hemanth> yup
hemanth> unlike bash!
jonsul> b the second because 0 cacels a
hemanth> remember 0 is true in Bash
hobs_limp and it it returns the first possibility of the or statement as a and b are both real
jonsul> *cancels
hemanth> :)
hemanth> >>> a=1
hemanth> if a == '2':
hemanth> print ('1a')
hemanth> elif a == '3':
hemanth> print ('3a')
hemanth> else:
hemanth> print ('1a')
manth NOTE that indentations
jonsul> 1a
hemanth> jonsul, correct ;)
jonsul> python's really a great language by the way guys
hobs_limp I also got 1a
hemanth> jonsul, can you tell us all a simple case example :)
hemanth> jonsul, case statement
jonsul> the best example is the indention for clean code, but I really like the dictionaries {}
jonsul> the clean syntax makes reading code extremely easy and fun
lakshmi> but sometimesn this identation is annoying
jonsul> not after you get used to it, then you wish other languages had it lol
hemanth> lakshmi, editor are good enuf, to care of it for you :)
jonsul> geany is a good open source one by the way
jonsul> OH!
hemanth> switch EXPR:
hemanth> EXPR:
hemanth> SUITE
hemanth> EXPR:
hemanth> SUITE
hemanth> ...
hemanth> else:
hemanth> SUITE
PaBLoX> jonsul: geany rocks ;)
hemanth> is how the switch case works
lakshmi> :) will try it
hemanth> emacs!
jonsul> I love the module system, if anyone's tried other languages you know why
hemanth> vim for few :P
PaBLoX> vim!
PaBLoX> haha
hemanth> Eclipse!
jonsul> emacs, but it's always a pain the the a**
PaBLoX> or if you want a better python interprether, you could use ipython or idle
hemanth> bpython
hemanth> have you guys tried bpython editor?
hobs_limp nope
PaBLoX> no
hemanth> you gotcha!
jonsul> emacs rocks if you know elisp! I give it that
hemanth> jonsul, i used to twitt from emacs ;)
jonsul> nice!
hemanth> okies if no o/, lets move on?
lakshmi> yes
hobs_limp yes
jonsul> yep
26SourRust_> yea
hemanth has changed the topic to: RUBY CE
hemanth> The Ruby language has a very simple control structure that is easy to read and follow.
hemanth> if
hemanth> btw, all of you switch to irb
PaBLoX> international rugby board :P
jonsul> k
hemanth> ha ha
hemanth> interactive ruby
jonsul> what's the good thing about ruby, that's one I have no experience with
hemanth> you will very soon
hobs_limp http://en.wikipedia.org/wiki/Why%27s_%28poignant%29_Guide_to_Ruby
hobs_limp read this
hobs_limp later
hemanth> irb(main):001:0> var=10
hemanth> if var == 10
hemanth> print “Variable is 10″
hemanth> end
jonsul> why the luck stiff?!! wtf LOL
jonsul> sry it's from the link
jonsul> it's the author's name
hobs_limp yep
hobs_limp that's his psuedonym
hobs_limp or was
hemanth> np :)
hemanth> if var == 10
hemanth> print “Variable is 10″
hemanth> else
hemanth> print “Variable is something else”
hemanth> end
hobs_limp got it
hemanth> if var == 10
hemanth> print “Variable is 10″
hemanth> elsif var == “20″
hemanth> print “Variable is 20″
hemanth> else
hemanth> print “Variable is something else”
hemanth> end
hobs_limp Variable is 10
hemanth> print “The variable is ” + (var == 10 ? “10″ : “Not 10″)
hemanth> ? is called as the Ternary operator
manth you need to look for ? in all languages as you update the h.w
hemanth> $age = 5
hemanth> case $age
when 0 .. 2
puts "baby"
when 3 .. 6
puts "little child"
when 7 .. 12
puts "child"
when 13 .. 18
puts "youth"
else
puts "adult"
end
hemanth> text malformed?
PaBLoX> hobs_limp: yeah, weird that he dissapeared :s (scary)
hemanth> $age = 5
hemanth> when 0 .. 2
hemanth> puts "baby"
hemanth> when 3 .. 6
hemanth> puts "little child"
hemanth> when 7 .. 12
hemanth> puts "child"
hemanth> puts "adult"
hemanth> end
hobs_limp I did some research, he "retired" pretty ungracefully. but more after class :)
hobs_limp>21 hemanth: could you put that in the etherpad
jonsul> yay! a story!
hemanth> done
jonsul> what's up with the whois? I've seen them posted on the logs too???
manth time to vote, 0 or 1
hemanth> continue or stop ? 0 | 1
jonsul> is this in bash or everything else? LOL
hobs_limp is it bash
hobs_limp you got me jonsul lol
hemanth> jonsul, need to filter them, whois gives if of ur ip and connection client and stuff
hemanth> O.K now 0 or 1
hobs_limp 0
26SourRust_> 0
hemanth> it's another 5-8 mins
PaBLoX> 0 (let's finish ruby)
jonsul> 0...
lakshmi> 0
hobs_limp if its under 10 I can stay
hemanth> PaBLoX, rb, done! its was just few simple conditional expressions
PaBLoX> oh
PaBLoX> haha
hemanth has changed the topic to: PERL CE
PaBLoX> uuu
PaBLoX> perl :/
hemanth> psh everybody
PaBLoX> the weirdiest synatx in the world
jonsul> I'm interested in ruby I just hate typing end after a block :/
jonsul> oops catching up^^
hemanth> data updated in etherpad also
hobs_limp you dont have to jonsul if it is one line
hobs_limp btw
jonsul> apt-get'n
hemanth> $gygy="London";
hemanth> if ($gygy eq "Paris") {
hemanth> print "The city is Paris. ";
hemanth> }
hemanth> elsif ($gygy eq "Tokyo") {
hemanth> print "The city is Tokyo. ";
hemanth> }
hemanth> else {
hemanth> print "The city is London. ";
hemanth> }
hobs_limp psh%
jonsul> o/
hemanth> irb(main):008:0> $today
hemanth> => nil
hemanth> irb(main):009:0> $day="today"
hemanth> => "today"
hemanth> irb(main):010:0> ($date == $today) ? print "Happy B.Day!\n" : print "Happy Day!\n";
hemanth> what do u notice?
jonsul> damn! duplicate sources error
hemanth> !?
hobs_limp I notice you are still in irb
hemanth> hobs_limp, good :)
jonsul> apt-get update^^ => psh%
hemanth> hobs_limp, now try the same in psh
hemanth> psh% $day="today"
hemanth> psh% ($date == $today) ? print "Happy B.Day!\n" : print "Happy Day!\n";
hobs_limp happy b.day!
jonsul> perl has regular expressions right?
hobs_limp haha
hemanth> nice :)
hemanth> jonsul, yes it does
hemanth> See this :
hemanth> use Switch;
hemanth> switch ($val) {
hemanth> case 1 { print "number 1" }
hemanth> case "a" { print "string a" }
hemanth> case [1..10,42] { print "number in list" }
hemanth> case (@array) { print "number in list" }
hemanth> case /\w+/ { print "pattern" }
hemanth> case qr/\w+/ { print "pattern" }
hemanth> case (%hash) { print "entry in hash" }
hemanth> case (\%hash) { print "entry in hash" }
hemanth> case (\&sub) { print "arg to subroutine" }
hemanth> else { print "previous case not true" }
hemanth> }
jonsul> ahh.. got to love em
hemanth> :)
hemanth> okies any o/ ?
hemanth> Suggestion : There is nothing complicated with these, you just need to try them slowly again
lakshmi> yes
hemanth> will be clear only if you do the home works :)
hemanth> if no o/ this ends CE!
hemanth> next up will be LOOPS
hobs_limp>21 thanks hemanth
hobs_limp peace!
lakshmi> thanks
hemanth> Sorry for taking extra time
jonsul> I didn't like them regexp when I first learned perl, but then I touched on them again in racket
manth likes interactive class :)
jonsul> learned they're pretty bad ass
hemanth> jonsul, RE's can be used in all most all languages
jonsul> yeah, but not all
hemanth> RE's are very obfuscated and less encouraged
jonsul> lol really
hemanth> any more o/ ??
PaBLoX> nope, fine for me
jonsul> didn't know that, lisp and perl are a bit dated though
jonsul> nope
hemanth> Thanks all :0) this is hemanth signing off, will catch u next week, Do your H/W's its fun ;) push them and send a pull request :)
SourRust_> ok cya
adam_collado> later guys
jonsul> hey wan't there gonna be a ruby story?
hemanth> jonsul, as in?
jonsul> hobs_limp on that author
hemanth> hobs_limp has quit ;)
PaBLoX> D:
PaBLoX> for the next time then
PaBLoX> btw
hobs> oh
jonsul> I see that lol, I'll have to catch him next time
PaBLoX> I don't have a perl shell on arch linux
PaBLoX> I just discover it
hobs> yeah he ragequat
PaBLoX> :/
hobs> after people outed who he was
hobs> deleted all his stuff
hobs> and quit the internet
hobs> totally self caused
hobs> ttyl!
jonsul> wow
jonsul> why'd he get pissed at that lol
jonsul> later
are fixed now, it was due
are fixed now, it was due to color highlighting done by an IRC client that i had configured with limpid!
I see some weird characters
I see some weird characters :/