Giniu
Members-
Content Count
222 -
Joined
-
Last visited
Everything posted by Giniu
-
Truely Annonymous Internet None of that Proxy rubbish
Giniu replied to qwijibow's topic in Websites and Web Designing
Yeah... also when you live in some countries you can be discriminated... for example pay-for-search-engine (Omega search) is well known to not work from Poland - you get only: "you are connecting from unsuported country" - they are blocking IP numbers from Poland (don't know why) - I use account just like others - so they shouldn't do what they do. So - things like this would allow me and others from "country black list???" (why?) use some service that normalny are blocked. And it is legal (I think) as long as you are doing legal things... so why not use it and get more secuirity? -
Truely Annonymous Internet None of that Proxy rubbish
Giniu replied to qwijibow's topic in Websites and Web Designing
That's great :)amazing tool... where did you diged it out? this would work with any connection, right? (ADSL, Dial-up, Broadband and so on?) -
I don't know if this method works, but I know what those files are for...Win XP in it's eye-candy-nes likes to preview image files since it thinks that you don't know what files you have on your own computer (who system should trust if not user? never mind...) and it creates Thumbnail previewss of them and store them in it's database that is created one by directory. And those files are named thumbs.db - they are created for "comfort" of use... to not wait for generating those previews every time you visit directory. You can turn them of and you can be sure that you have those files when you use explorer to browse directories in which you have images... use for example Total Commander or similar to prevent creating those files if you wouldn't be able to turn it off...
-
Win 2k Pro Won't Install dual boot mishap etc
Giniu replied to moonwitch1405241479's topic in Websites and Web Designing
This is best decision that can be taken... :)As far as I know... Photoshop works great in wine (In standard Wine and CrossOver also...) - you don't need to have windows to work in it... also Linux can use windows ttf fonts almost just like any others. And if you don't want to force systm to use MS ttf - you can convert them (also modyfi if license lets you) with FontForge (Why use fonts created by others? Make your own ) and have all you need at one time at one machine -
Question About: Mbr And Win2003 Ent can be short yes-no :)
Giniu replied to Giniu's topic in Websites and Web Designing
Thanks... that is what I thougth it would be... :/How-to's you say you know how it is with dual-booting... you can find 100 of them, and 50 would say: "install bm to mbr!!!" and 50 others would say: "never install bm to mbr!!!" and I choose to install into mbr, but to keep all files on separate partition - so reverting lilo would be one command... the only thing...would Win2k3 be working when I would remove the "winthing mbr"? I don't want to loose time if it wont be working... :)Oh... Qwijibow... when I started to write it I didn't saw your post... wonder why :)If I created partition for Windows with Linux? yes... but only becouse I didn't want to format wrong partition while installing windows ... as I remember it see that it is ntfs? don't it? anyway - this is only to not see 10 unrecognized partitions... thanks for your answer... -
Hi...Right now I'm windoze free and happy Linux user, but in few months I need to install Windows becouse of study - damn - only Visual C++... so I decided to install it and take a closer look at it... I downloaded my copy of Windows 2003 Enterprise from MSDNAA (Microsoft Development Network Academic Aliance or something like that...) and burned iso to cd (of course I would install it only once then I would destroy the cd... strange rules )... I prepared place for it (10gb is I hope enougth - I have 140 but I don't want to loose too much from real OS for some toys...) so I made free space at begining of hard drive and repartition and reconfigured linux to have hda1 free, also formated it to ntfs and everything worked... Now I have free ntfs partition at begin of hard disk, working Slackware and need to ask one question to proceed:Is Windows 2003 Enterprise cleaning mbr while installing to install some of it's trash? I have lilo in mbr, so I don't want to loose it - of course the only thing would be instering disk into floppy and running lilo to get it back, but I don't like this way... If it would left mbr or if there is a way to make it not touch it it would be great...any advice would be apreciate...I'm sorry - if you are Stcky Windows user my words may hit you - but I can't change my soul...
-
Win 2k Pro Won't Install dual boot mishap etc
Giniu replied to moonwitch1405241479's topic in Websites and Web Designing
Think I can help you... Seems you need to clean mbr, install win2k and then revert mbr of your linux... to clean mbr - boot from win2000 cd, choose repair (recovery console or something...) and give command: fixmbrand you would get clean mbr, then you can install windows and all you have to do now is revert linux loader... boot from floppy and give command: liloto overwrite it into mbr. Now only some config and you are running dual-boot... If you are using grub - I can't help you reverting mbr, since I never used it - I'm stick with LiLo... Hope this will help you and you would have your full system soon SeeYa. Giniu ------------ PS.: Bonkers - moving toward XP isn't good idea - it is still almost same system but works a lot slower than 2k - only thing you get installing XP are some eye-candys and lower performance... so just ask yourself - why? -
Parampampam...I should read also other posts of you... sorry - not there - it would be there if you would apply for free web hosting... just ask M^e or Nilsc and they should direct you to right place...one more time sorry...
-
Hi... as far as I know it is possible to have it, but for default it is disabled, becouse not everyone needs it... to enable it just post in [ Free Web Hosting: MISC Requests ] that you need it and wait usual request time... (like when you request your account).
-
Konnichiwa, Mina-san! (nah, I'm Not From Japan) ... but from Poland
Giniu replied to L-Voss's topic in Introductions
Hi L-Voss... (no nie mów... coraz więcej nas tu )...after this short prefrase to official part...Weclome you for sure would love this board like we all... Don't tell you also learn Japanese... right now I have short time, but this is language that I would choose in next year on studies... How advanced are you?You said that you translated some roms to PL from English... is FF5 your work, or you work on other rom's? I'm just curious if I use your work or not You would probably also like to take a look at Antilost if doesn't already - take a look if not... http://forums.xisto.com/no_longer_exists/ and visit board there... this is site runned by our great M^e and highly connected with Xisto...And for the end of post... can you tell me from what city you are? My real name is Andrzej and I'm from Wrocław... so who knows... maybe we are neightbours? -
Mastering Erlang part 2 – Erlang Sequential Or: Writing separate modules And there it is... as I promised here is second part of Erlang tutorial – it wasn’t long since I’ve got some time and doesn't have anything to do... First of all review what you should already know/have: Installed Erlang and know how to start and quit from Erlang Virtual Machine (shell). Know how to create and what name should have Erlang source files. Know how to compile source you’ve just created. Have some free time that you want to spend learning Erlang. Ok... so I believe that you know/have all this... if you lack first three points refer to first part of this tutorial, if you lack fourth point, come back other time and you will be able to start over. I’ll try to keep it as short as possible, because introduction was in separate tutorial... Some lazy part – or Number, booleans, expressions and operators I think that first thing I should discuss is number expressions – currently we’ll talk only about them in shell not in modules, so you can start it and I’ll begin... (remember every line in Erlang that is definite over must have dot at the end) Number expressions in Erlang are it's strong point – the only limit to number expression is amount of user's memory so you don't have to worry how large result will be (theoretically) and how much of memory reserve for it. Erlang understands numbers written in classic decimal notation that are integer: 12345. or float: 123.45. they can be positive: +5. which is same as: 5. or negative: -5. it can also understand float numbers written in positive exponents mode (number multiplicated by 10 given to power n): 123.45e3. which is the same as: 123.45e+3. there can also be floats written in negative exponents mode: 123.45e-3. But decimal base isn't only one that Erlang can understand, Erlang understands any base from 2 to 36 by only giving the base and number like this binary base: 2#1001101. or hexadecimal base: 16#1fa2. Also useful way of writing numbers is interpreting of character ASCII codes by just typing: $A. or when you cannot type the letter, by: $\n. As you see there are many ways of number interpreting in Erlang... there are also others values you can assign, like booleans which interpretation in Erlang is very easy: true. means true and for instance: false. means false - you can do some compares on numbers and get booleans. You can check if expression1 and expression2 are equal: expression1 == expression2 or not equal: expression1 /= expression2 also less than or equal: expression1 =< expression2 less than: expression1 < expression2 greater than or equal: expression1 >= expression2 greater: expression1 > expression2 All those comparisons work for any types – also when comparing different types, so 1 == 1.0 returns true... there is way for do exact comparisons – exactly equal to look like: expression1 =:= expression2 and exactly not equal to: expression1 =/= expression2 there are few examples with returned values of “equal” and “not equal” so you can better understand them: 1 == 1 (true) 1 /= 1 (false) 1 =:= 1 (true) 1 =/= 1 (false) 1 == 1.0 (true) 1 /= 1.0 (false) 1 =:= 1.0 (false) 1 =/= 1.0 (true) 1 == 2 (false) 1 /= 2 (true) 1 =:= 2 (false) 1 =/= 2 (true) So... you can now compare two numbers – but now – lets make some numbering arithmetics so you can do better comparisons. You can add two numbers: a + b subtract: a – b multiply: a * b floating point divide: a / b from this point arguments cannot be float – they must be integer. First of integer operands is integer divide: a div b get reminder of a / b: a rem b that are all classic arithmetics available in Erlang (rest are functions in math module), but there are also bitwise arithmetics, like unary bitwise not: bnot a bitwise and: a band b bitwise or: a bor b bitwise xor: a bxor b bitshift left: a bsl b bitshift right: a bsr b I think that all this requires some examples (I write for example a + b = c without classic Erlang writings to keep it short...) 2 + 2 = 4 2 + 3.1 = 5.10000 4 – 2 = 2 4 – 2.1 = 1.90000 2 * 2 = 4 2 * 2.1 = 4.20000 4 / 2 = 2.00000 4 / 2.1 = 1.90476 4 div 2 = 2 4 div 2.1 (error) 5 div 2 = 2 6 div 2 = 3 4 rem 2 = 0 5 rem 2 = 1 6 rem 2 = 0 bnot 0 = -1 (0=...00000000; -1=...11111111) bnot 1 = -2 (1=...00000001; -2=...11111110) 7 band 8 = 0 (7=...0111; 8=...1000; 0=...0000) 7 band 12 = 4 (7=...0111; 12=...1100; 4=...0100) 1 bor 1 = 1 (1=...01) 1 bor 2 = 3 (1=...01; 2=...10; 3=...11) 1 bxor 2 = 3 (1=...001; 2=...010; 3=...011) 3 bxor 6 = 5 (3=...011; 5=...110; 2=...101) 2 bsl 1 = 4 (2=...0010; 4=...0100) 3 bsl 2 = 12 (3=...00011; 12=...01100) 12 bsr 1 = 6 (12=...01100; 6=...00110) 7 bsr 2 = 1 (7=...0111; 1=...0001) So you should know how to make some arithmetics... try them all and remember to put dot at end, like: 1>2+2. 4 Now you can see that comparisons are a little better: (2 + 2) == (7 band 12). is true... but this is still weak, we need also some boolean expressions to see tell what if something or something will happened... first is simplest one – unary logical not: not expression we have also logical and: expression1 and expression2 logical or: expression1 or expression2 and last one – logical xor: expression1 xor expression2 again lets look at some examples: not true = false not false = true true or false = true true or true = true false or false = false true and false = false true and true = true false and false = false true xor false = true true xor true = false false xor false = false Those basic boolean expressions gives large power and now your comparisons can looks like: (2==2) and ((2+2)==(7 band 12)). will return true. Sometimes evaluating expression takes very long and most languages still evaluates them – for example they first evaluate left then right side of and operator and then returns value – true or false... but this can take long... and what if on left we will get false? Other languages and this method in Erlang also counts right side... but there are special short-circuit boolean operators that allow to check only left side and right side only if needed. First of those two operators is orelse: expression1 orelse expression2 will check expression1 and if it is true, will return true for whole expression and if expression1 is false it will return expression2 without checking it. Second short-circuit boolean operator is andalso: expression1 andalso expression2 this checks expression1 and if it is false, whole expression returns false, if expression1 is true, Erlang returns expression2 as result of whole expression. The effect is same as using usual “or” and “and” but this way is a lot faster. Unfortunately this cannot be used in “guard” like in “case” or “if”, but I will talk about this later... It’s the end of this long chapter – now you can use numbers and booleans in Erlang... we’ll be coming back to other data types as we’ll need them – now let's do something more interesting... Hearth of Erlang – or Functions and variables Erlang as you know from previous part of this tutorial is functional language, it contains almost only functions and they are most important part of language. I’ll discuss functions using several examples, but first few words about variables. In Erlang there is one thing that confuses at start – one variable can be bound only once in one function – so when you write N=2 this is correct but then N cannot change it's value, if you write N=N+1 you’ll get error, but writing M=N+1 will be all right with exception that now M=3 and you cannot bound M to any other variable. This makes special use of recursion in Erlang that is real fast because of that. But some more about variables – variables names can be any string staring with upper-case letter or underscore, containing only letters, numbers, underscores and “@” signs. Some good defined variables are: X N Variable Variable1 Other_variable _myVariable1 _other_myVariable@somewhere but not: x n variable# or anything else that violates rules. Underscored variables like “_myVariable1” wont be reported by compiler if it is unused – this is difference to usual upper-case letter variables, which are strictly reported, Erlang is very strict about errors and informs you about all disfunctions of your code. There are special types of variables, anonymous variable – it is used when you have to get value, but you don't care what that value is and don't want to store it anywhere. Anonymous variable is underscore “_”. Later on I’ll tell in what situations anonymous variable are used (when you match tuples or lists, but this is not the place for this now). You can test variables also in shell without need to write module. We’ll try now: N=1. You assigned value “1” to variable “N”, now call it: N. And you get value. Also see that you cannot assign value to N: N=2. gives you error – this is one of confusing things in Erlang, but you can get used to it. In shell you can see what variables are binded by using function: b(). from “bindings”. Then you can remove binding to some variable (warning – this works only in shell) by using function: f(Variable). From “forget” or unbind all variables: f(). You can also see last 20 commands by using function: h(). from “history” and execute n-th command in history by: e(n). from “evaluate”, or execute last command using function: e(-1). This works of course only in shell and can be useful when you are trying many examples with different variables. Now let's take a closer look at modules and functions, first I’ll give you some general look of function: function(Patern1) -> Action1, Action1, Action1; function(Patern2) -> Action2, Action2, Action2; function(Patern3) -> Action3, Action3, Action3; ... function(PaternN) -> ActionN, ActionN, ActionN. Which can be extended with guards. But I won't explain it now - we analyse example that returns number e, then we add few functions and everything will show when it should. We call this module mymath. Create appropriate file that contains: -module(mymath). -export([e/0]). e() -> 2.71829. now compile it and run: mymath:e(). and you got right value... so now – lets explain it: -module(mymath). Names the module so it can be called – rather easy thing – just name. -export([e/0]). Function e containing 0 arguments can be called outside this module – any other function can be called only from this module. e() -> If function e is called without arguments, it returns... 2.71829. this value. So... this one was easy, right? Create something more... let's add famous factorial to our module: -module(mymath). -export([e/0, factorial/1]). e() -> 2.71829. factorial(1) -> 1; factorial(N) -> N * factorial(N-1). So let me explain (only lines that changed): -export([e/0, factorial/1]). Function e containing 0 arguments and function factorial containing 1 argument can be called outside this module – any other function can be called only from this module. factorial(1) -> If function factorial is called with one argument that is equal to 1... 1; return one, but this is not end of function, because... factorial(N) -> If function factorial is called with one argument that isn't equal to 1... N * factorial(N-1). Return that value multiplicated by value of factorial from one less (this starts recursion, because function factorial is called again, and again, and again... until it will be factorial from one) and this is end of this function. Well this example works – but has a large bug – it can hang when we call it with value smaller than 1 – to count factorial(0) it needs factorial(-1), to count factorial(-2) it needs factorial(-3) and so on – it stops after you kill it or computer hangs from lack of resources... let's modify it with when command and a guard (condition)... also let's include 0!=1 and some easy information that wrong number was typed (returns -1 when other fails): -module(mymath). -export([e/0, factorial/1]). e() -> 2.71829. factorial(N) when N>0 -> N * factorial(N-1); factorial(0) -> 1; factorial(_) -> -1. we have some changes only in factorial function block – as you mentioned (or not) function are checked from top, and if some suites given conditions don't even look at others... ok – so let's explain this one: factorial(N) when N>0 -> this is easy – it do what it says - If function factorial is called with one argument that greater than 0 (the condition after word “when” is called guard. I’ll tell you something about them right after this example)... N * factorial(N-1); Return that value multiplicated by value of factorial from one less... factorial(0) -> If function factorial is called with one argument that is equal to 0... 1; return one, but this is not end of function, because... factorial(_) -> when value wasn't greater than zero, and wasn't zero – it must me less than zero, so (we know that there is some argument, but we don't care about it, we use anonymous variable because we don't want to set memory for nothing) we... -1. return value -1 that can be interpreted by us as error. And this is end of our function. This isn't also good – how someone can know that -1 means to you error? I introduce now function format from module io, that allows you to write something to Erlang shell – right now I won’t tell you about all it's features, but that to write plain message, use something like this: io:format("message~n", []). you’ll understand why we use that [] when you’ll know about lists – now this is enough to fit our example: -module(mymath). -export([e/0, factorial/1]). e() -> 2.71829. factorial(N) when N>0 -> N * factorial(N-1); factorial(0) -> 1; factorial(_) -> io:format("WARINING!!! Factorial can be counted only from numbers larger or equal zero!~n", []). This don't require more comment – I think so... like I promised – I’ll tell something more about guards... As guard you can use any condition and special functions, like: is_number(X) - X is a number is_integer(X) - X is an integer is_float(X) - X is a float is_atom(X) - X is an atom is_tuple(X) - X is a tuple is_list(X) - X is a list A == C - A is equal to C – you can use any condition you can join guards into guard sequences, when you separate them with coma, guard sequence would be true if all guards are true and when you separate guards with semicolon, guard sequence is true when any of guards is true. So what if in our example someone calls function with number that isn't integer? We shouldn't count then... and when someone calls, it gets error – some things cannot happen – so let's modify our example: -module(mymath). -export([e/0, factorial/1]). e() -> 2.71829. factorial(N) when N>0,is_integer(N) -> N * factorial(N-1); factorial(0) -> 1; factorial(_) -> io:format("WARINING!!! Factorial can be counted only from integers larger or equal zero!~n", []). I feel that I don't have to explain this to you – compile it and try different values... this is first step into robustness in Erlang, but now at sequential stage. Now as exercise extend our example with function “add” that adds two given numbers, make sure they are numbers, if not – inform about error. Structures of Erlang – or Atoms, tuples and lists I believe that when you was adding this function you was interested – how can I add for example values in centimeters and in meters? How Erlang would know what add to what? We can do this several ways – fist – easy one, that introduces atoms and tuples, it will be divided into three examples... first we’ll talk about atoms... atoms are literal values – they are it's own type... but look out – they are VALUES not VARIABLES so you cannot assign to them, but you can assign them. Atoms should start with lower-case letter, can contain letters, numbers, underscore and “@” sign. If you want them contain some other characters, give them in single quotes. There are some examples: this_is_atom thisAlsoIsAtom 'And this also...' Ok... let's see some example that print lengths: -module(length). -export([printlength/2]). printlength(N, cm) -> printcm(N); printlength(M, m) -> printm(M). printcm(N) -> io:format("there is ~w centimetres~n", [N]). printm(M) -> io:format("there is ~w meters~n", [M]). I think that this example requires some explanation... outside we have function printlength with two arguments... now let's explain functions: printlength(N, cm) -> printcm(N); if second argument is atom “cm” we call inner function primtcm with value from argument one as it's only argument... printlength(M, m) -> printm(M). and same there - if second argument is atom “m” we call inner function primtm with value from argument one as it's only argument. The inner functions have looks like this, but to explain why, I first must you tell about lists and this will happened soon. Now try this example with few values, like: length:printlength(25, cm). or length:printlength(4, m). now... this is a bit confusing – if for example we would like to convert something we cannot use something like that, because we wouldn't be able to tell from and to what we are converting... so Erlang allows us to bind some values together and create a tuple. Tuples can bound any number of variables, like: {5, cm} {1, 2, 3} but they can also be nested: {5, {1, 4, {2, {cm}, 2}, 1, 1, {2, 2}}} so, we can use things like first line of this example to specify that 5 is in centimeters. Let's modify our example: -module(length). -export([printlength/2]). printlength({N, cm}) -> printcm(N); printlength({M, m}) -> printm(M). printcm(N) -> io:format("there is ~w centimeters~n", [N]). printm(M) -> io:format("there is ~w meters~n", [M]). this easy modification doesn't require more explanation... call modified function by: length:printlength({25, cm}). or length:printlength({4, m}). now if we are converting, we know that 25 is in centimeters and 4 is in meters because they are binded with each other. But tuples aren't also enough for most problems... we have to know what number of elements it have... and how can we add many values? There with help comes lists... lists can looks like: [1, 2, 3, 4, 5] they can also contain values of other types like for example tuples or atoms, or all of them at once: [{1, 4}, {1, 3, 4}, mc, 21] Now... let's see some example and I’ll explain it: -module(addmany). -export([addmany/1]). addmany([]) -> 0; addmany([First|Rest]) -> First + addmany(Rest). And now some explanation: addmany([]) -> 0; sign [] means empty list, so – if list is empty return 0, and if it isn't: addmany([First|Rest]) -> First + addmany(Rest). Interpret list as [First|Rest] – something like [ ... | ... ] is extracting – it extracts first list element and bind it to variable First, and rest of list will be binded to variable Rest. More about tuple and lists matching goes just after some example that covers all of above three examples... but back to this example, it extract first element and returns sum of it and of sum of rest of list – this is also recursion... Now let's gather this example and create module that doesn’t add lengths in meters and centimeters and give us results in centimeters: -module(addlength). -export([addlength/1]). addlength([]) -> 0; addlength([First|Rest]) -> addelement(First) + addlength(Rest). addelement({Value, cm}) -> Value; addelement({Value, m}) -> Value * 100. and now try this example: addlength:addlength([{1, m}, {32, cm}, {17, cm}, {2.4, m}]). You should get 389. So now you see that list combined with tuples and atoms are real powerful tool. Now few word about matching of tuples... This exercise will be made in shell so start it and you will be able to do it during reading... Tuple can be binded only to tuple with same number of elements or single variable, try: A = {1, 2}. and {B, C} = {1, 2}. or {B, B, C, C, C} = {1, 1, 2, 2, 2} now try: A. B. and C. so you know how it works... but sometimes you don't care about value so you can use anonymous variable: {_, D} = {wontseeme, yes}. Now try: D. So... this is all about tuples you should know now, but now let's take a look at matching of lists... there is something more... We’ll play a bit with lists: E=[1, 2, 3, 4, 5, 6]. E. gives [1, 2, 3, 4, 5, 6] [L, M]=[1,2]. L. gives 1 M. gives 2 [F|Rest]=[1, 2, 3, 4, 5, 6]. F. gives 1 Rest. gives [2, 3, 4, 5, 6] [G,H,TheRest]=[1, 2, 3, 4, 5, 6] G. gives 1 H. gives 2 TheRest. gives [3, 4, 5, 6] [I, J | K] = [1, 2]. I. gives 1 J. gives 2 K. gives [] Low let's see some examples that returns errors: {A, A, B} = {1, 2, 3} {A, B, C} = {1, 2} [A, A, B] = [1, 2, 3] [A, B, C] = [1, 2] so as you see when you match list with list and tuple with tuple size and length should be same and you shouldn't assign different values to one variable. So as you see – lists are one of great Erlang things, you can change order of list, search for some elements, count their length... they can be compared to arrays from other languages, but you don't have to reserve memory for them so they can grow as far as you want while using ready application. I told you that I would explain a little about io:format – so there it goes – function format from standard module io gives you chance to write output to shell, I won’t tell you everything, because you now don't need to know more... it contains two arguments: first a string with break sequences (like ~w and ~n) and with with list of arguments... every argument from list is entered into place of ~w break sequence, ~n sequence means new line. There are some examples: io:format("This is test when we have one variable:~w... did you saw that?~n", [Value1]). io:format("And now we have two variables:~w~w did you saw that? No space and enter?", [Value1, Value2]). io:format("Ahh... I forgot about that:~w ~w!~n", [Value1, Value2]). This should be enough about that right now, but if this is not enough, run Erlang like this: erl -man io To get help about module io. As exercise write module that contains tree functions: reverting list, finding max and min and returning it as tuple {min, max} also counting it's length – don't use pre-made functions or built in functions – this is exercise so do your best – only exception can be module io. Conditions in Erlang – or If and case First I’ll take care of if command – and again – in Erlang it looks different than in most languages... it doesn't have “else” but can have many conditions. Generally it looks like this: if GuardCondition1 -> Action1; GuardCondition2 -> Action2; GuardCondition3 -> Action3; ... GuardConditionN -> ActionN end so – this is how it looks like – it checks if condition1 is satisfied and if yes, activates action1 and don't looks for other condition, but goes where end is – if you want to use “else”, just add as many conditions as you want and you’ll get even better result, you also can use “true” as condition to make sure something will happened, if no condition is true, error would happened and you don't want it to came up. There is small example of function using if, but I won't analyze it, you should made it by yourself: compare(X, Y) -> if X>Y -> greater; X==Y -> equal; true -> less end. Guard conditions in if can be joined using comma (Expr1,Expr2 - both must be true) or using semicolon (Expr1;Expr2 - just one them must be true), take a look at this example: compare(X, Y) -> if X>Y,Y>0 -> positive_x_is_largest; X==Y -> equal; X<0 -> x_is_negative true -> less_or_different_signs end. In Erlang there is also other construct that allows conditional execution, it is case – this is how it looks like in general: case Expression of Value1 -> Action1; Value2 -> Action2; Value3 -> Action3; ... ValueN -> ActionN end In Erlang case is very similar to if. It can be the same as if command if it's formed like: if Expression==Value1 -> Action1; Expression==Value2 -> Action2; Expression==Value3 -> Action3; ... Expression==Value3 -> ActionN end Case can have addictional guard sequence – then it looks like: case Expression of Value1 when GuardExpression1 -> Action1; Value2 when GuardExpression2 -> Action2; Value3 when GuardExpression3 -> Action3; ... ValueN when GuardExpression4 -> ActionN end Action is executed when Expression is equal Value and GuardExpression is true. If any Value and GuardExpression cannot be satisfied, error occurs. You can get “else”-like instruction, by giving anonymous variable as last value and true as last GuardExpression (or by not giving last GuardExpression). Some example use of case can looks like: case Length of {X, cm} when X>0 -> Length; {Y, m} when Y>0 -> Length * 100; _ -> 0 end Now you have powerful tool – test clauses of Erlang... this is time for you to show up some invention... there is the exercise: Write module that takes two dates and gives how many days there was between them (form same dates there is 0 days). Hint: use tuples to keep dates and some cases to find out what year have a leap, make sure right dates are given, check if months don't have too much days, year too much months, first date isn't before second one and so on. You should be able to accomplish this without troubles... Power of functional language – or Build-in functions and higher order functions This is last part of informations needed to unleash Sequential Erlang. First I’ll give you some information about BIF's – which stands for Build-in functions. Complete list of Build-in functions can be found in man pages for Erlang. There are only some of them, they are all from module erlang, so you don't have to put module name before them: date() – returns date in tuple (like {year, month, day}) time() – returns time in tuple (like {hour, minute, second}) trunc(Number) – returns truncated number (like 6 -> 6 but 5.6 -> 5) round(Number) – returns rounded number (like 6 -> 6 but 5.6 -> 6) length(List) – returns number of elements in list (like [1,2,3,4] -> 4) size(Tuple) – returns size of tuple (like {1, 2} = 2) float(Number) – converts number to float (like 5 -> 5.00000) is_atom(Element) – returns true if Element is atom, else return false is_tuple(Element) – returns true if Element is tuple, else return false is_list(Element) – returns true if Element is list, else return false atom_to_list(Atom) – return list that contains atom (like atom -> “atom”) list_to_atom(List) – returns atom that contains list (like “list” -> list) integer_to_list(Integer) – returns list that contains integer number (like 22 -> “22”) there are much more Build-in functions that can be used – like I said earlier complete list of them is in manual pages for erlang (erl -man erlang). This is all I say about BIFs – now the real power – higher order functions – The higher order function looks like this: fun (Patern1) -> Action1; (Patern2) -> Action2; (Patern3) -> Action3; ... (PaternN) -> ActionN end higher order function can also take extra Guard (when) parameter and looks like: fun (Patern1) when Expression1 -> Action1; (Patern2) when Expression2 -> Action2; (Patern3) when Expression3 -> Action3; ... (PaternN) when ExpressionN -> ActionN end fun should be assigned to variable and then it can be called be calling it's assignment name. This can be seen in this shell example: Function = fun ({X, cm}) when X>0 -> io:format(“~w~n”,[X]); ({Y, m}) when Y>0 -> io:format(“~w~n”,[Y]); (_) -> 0 end. And now we can call it by typing: Function({20, m}). or any other value like in earlier example. This gives us real large power. In module lists there is function foreach that looks something like this: foreach(Fun, [First|Rest]) -> Fun(First), foreach(Fun, Rest); foreach(Fun, []) -> ok. We use it's predefined version (lists:foreach) to demonstrate it's use on our function “Function”, type in shell: lists:foreach(Function, [{20, cm}, {5, m}, {3, m}, {1.2, m}]). in lists module there are also other useful functions, but one I mention there – it is map – it looks like: lists:map(Function, List) and calls Function for every element in List. The result is also stored in List. If for example you have function that adds one to element and call this: lists:map(add1, [1, 2, 3, 4, 5]). you’ll get: [2, 3, 4, 5, 6] As you see you can change behavior of module not by calling different functions but by substituting function instances. Understand of fun object is one of most important thing. Read manual for erlang module and take a closer look at other BIFs, because you will be using them many times. Now as exercise rewrite all modules from exercises using build-in functions and higher order functions, make sure module won't hang when you give wrong values and won't crash with Erlang error, but gives information what is wrong, especially when you will be modifying exercise from part about if and case – do some research about module io (use manual pages), find out how user can input character while application is running, make him enter his date of birth, and calculate how many days he lived. Make input function a separate one, export three of them – one that asks for date of birth, second in which date of birth is given through arguments and third in which two dates are given thought arguments. This one should take you some time – if you want to make them good – remember – Erlang cannot crash – on real-time systems crashes are critical – If you won’t take care – a plane falls!!! This is the end of this part. You know all basic ways of sequential programming in Erlang. Next time we will take care for concurrency, so I will discuss more module options and module communication. Be sure to understand this part because you will have hard times going through next one. If anything from this or earlier part requires some more explanation – just post information there or PM and I will try to do my best to help you. Next part will take some time to write – sorry... but I think that you will have something to do And at least – when Erlang Everyday comes to true, I will fill holes in sequential and concurrent Erlang so you will be able to create even complicated applications. This one is long way too long, so see you next time -------------------------- Thanks for correction of this tutorial goes to Nelle... Big thanks... PS.: The copy of this tutorial is at AntiLost... there are still edit buttons so all changes/fixes would be made there... if you want to take a look and see if something changed, go to http://forums.xisto.com/no_longer_exists/ and visit board. SeeYa next time...
-
Future King Of Rpg? What shoud have a RPG to be best?
Giniu replied to Giniu's topic in Computer Gaming
a lot of good ideas... taken best and noted on board - it is staring to make sense... still collecting information to get as good concept as I can... thank to you all for help, I apreciate it and still waiting for new ideas -
Nope - it isn't free but you can get it for almost free - I bought it yesterday... in Poland it was sold with GameStar for 2.5$ - this isn't very high cost, don't you think? But this game is worth even 25$ not only 2.5$ Just take look around - it is 2 CD's...
-
Mastering Erlang Part 1 – Introduction Or: Erlang, installation and basic usage
Giniu replied to Giniu's topic in Programming
Finishing part two - should be there in next two or three days... while this I realized that you might wan't to get some editor that is capable to highlight erlang stntax... if you are *nix user you probably already have it, it is: vim emacs they are hardcore standards for programing... if you are using windows, mac or just like gui also in unix I can recomend you (with hand on my hearth): jEdit - from [it's homepage] - it has highlighting for more than 130 languages and (with plugins) builded in anything you want - for example independent CVS interface... it is written in java so requires it to run... -
I would try... anyway - you said FreeCiv 2.0 Beta is out... I would say more... FreeCiv 2.0 Final and even hot release 2.0.1 is out...
-
Mastering Erlang Part 1 – Introduction Or: Erlang, installation and basic usage
Giniu replied to Giniu's topic in Programming
Oh... I forgot about thing that don't suit into other parts... the comments in Erlang starts with "%", like in our example: %this module is my own addiction to math module-module(mymath).-export([factorial/1]).factorial(1) -> 1;factorial(N) -> N * factorial(N-1).hope I won't forgot anything else... keep up - I'm finishing second part now -
Mastering Erlang part 1 – Introduction Or: Erlang Virtual Machine – what it is, installation, usage... Warning! This tutorial is written for Erlang R10B4 – If you want use it with other release – consult with official documentation for possible incompatibilities and changes! What is this all about? - or Background Erlang is concurrent functional programming language developed in Ericsson Computer Science Laboratory, its development was started in 1987 after five years of researches on Lisp, Prolog and Parlog. Erlang was designed to be a very high level symbolic language with concurrency and error recovery. In 1990 Erlang was presented on ISS'90, one year later after Telecom conference Erlang was released to users with many new features like compiler and graphical interface. In 1993 Erlang was improved with distribution and after that Erlang started to grow even faster. Right now most popular Erlang implementation is Open Source Erlang which is distributed with OPT (which originally stands for Open Telecom Platform – a division of Ericsson which had to provide support for Erlang software) – a large collection of libraries for Erlang to do everything from compiling ASN.1 to providing a WWW server. Now when you use Erlang, you almost for sure use Erlang/OPT. As you mentioned main Erlang purpose is telecommunication, but it also have some success in for example 3D graphics world – Wings 3D – one of best Open Source modelling application is entirely written in Erlang. Current version of Open Source Erlang/OPT is 5.4.5 which is distributed in package called “Release 10-B, patched 4” or short “R10B4”. Release 11 is under high development and probably would see daylight soon. Why I'm writing this tutorial? Because I think Erlang is good language that isn't well known and I think it can be easily changed when you would know what it can do and how easy it is when you know it's philosophy. This tutorial would be divided into few parts, since my time doesn't allow to write everything at once... so what parts should you expect? Here is my plan: Introduction (who knows... you are reading this ) Erlang Sequential (about sequential programming in Erlang) Erlang Concurrent (about concurrency in Erlang) Erlang Everyday (about headers, macros and records in Erlang) Erlang Robust (about error handling and time-outs in Erlang) Erlang Distributed (about distribution, ports and security in Erlang) Erlang C (about cooperation of C and Erlang) Erlang Graphical (about using GUI, Open GL and SDL in Erlang) Perhaps more if there would be any feedback OR I would have free time Further reading: This tutorial is based upon original documentation, if you want to find out more than I wrote, look [there]. What you can suspect after this part? There is what it contains: Some background – look above... I think this is enough for it Terminology – I would explain terminology I would use later in this and other parts Installation of Erlang – I would explain installation of Erlang (based on Linux, other *nix requires modifications) Installation of ESDL – It would be needed later... (based on Linux) Short note on Windows compilation – just that it is possible... Note on Wings 3D – great Erlang application Basic usage – I would explain basic usage of Erlang Virtual Machine and one example program. So after this background I think it is time for start this show... You say what? - or Terminology Most important in Erlang is to understand its features, so let me explain most important things, they’re not sorted alphabetically, but by importance and terms: Programming language – I think that you’ve already known what it is, but maybe not, so there is strict definition... A programming language is language which programmers use to create programs – this language is then translated to binary code of machine so users can run program. This is simplest definition because there is no need to give you more complex one. Source code – Code of program/application written in specified programming language. Compilation – An automated process in which source code is translated to binary code that can be executed. Library – Pre made sets of functions that may be used in code to simplify creation of some effects. Usage of libraries best described by sentence: “Why need to re invite wheel?”. Module – Part of program that can work separately but almost always are parts of larger programs – for example key listeners (they can wait for key press and when they spot it, they send which key was pressed to standard output – for example terminal or printer) Virtual Machine – Environment that lets you to run programs independent on operating system and machine type, it is program that mediates between your program and operating system so you don't have to worry if you create program only for one operating system and it won’t work on others (in practice – you sill have to take care for it, but not as much as during creating application in language that runs without virtual machine). Functional programming – Programming methodology that threads computations as evaluation of mathematical functions. Almost everything you write in Erlang is created from functions so code is easy to read and you don't have to know whole bunch of keywords – only understand what you want to do. Distributed programming – Way of creating applications that run on many machines connected into network and send result to one or all of it. This is way of cooperation between parts of application that work even on second side of globe. Sequential program – Program that would be executed line by line, in sequential programming you may use loops and tests, but this gives only limited freedom... Erlang of course can use sequential programming, but it isn't its main feature. Concurrent program – Program that is created from modules, that runs separately on one or few machines and communicate with each others. Erlang is designed for concurrency so this is its power, it is designed for real-time system on which shut-down can be critical, so programs must run all the time (flight control, banks, telecommunication... there are many examples)... In Erlang this is used so good, so you can modify program (upgrade, recompile, anything...) while it is running and if it is designed well, it even wouldn't slow down while you would be doing that. High concurrency of Erlang allows you to create distributed application from stationary one almost without any modifications (only one line per module) so as you see this gives you large freedom. I think that now you would know about what I'm talking about. If you know other programming language, you probably knew that already, but this tutorial is for all – those that doesn't have experience with programming in other languages and those that have it, so be patient if you read it and think that I write very basics. But let's install the beast... Want to run it... - or Erlang Installation First of all you have to download Erlang – If you are using Windows, you should download pre compiled binary, because you can have troubles getting source code to work – If you are using other platform – you should download source code and man pages – the HTML documentation is optional. There is address from where you can download it from [there]. If you downloaded pre compiled binary – you already have documentation and installation is very simple – you must run installation exe and everything would be done automatically... but you would get less performance... perhaps on Windows you even wouldn't get large speed up... So you know how to install Erlang on Windows... but what about other platforms? So now I would explain compilation of Erlang: Unpack source code you downloaded (It is in .tar.gz file, so you can do for example (on Linux system): tar -xzf file.tar.gz -C target_directory Change directory to source files: cd target_directory/otp_src_R10B-4 Set lang environment to C: export LANG=C Now you must think about options for compilation... first is: --enable-threads which is required on systems that use thread (line Linux and also most Unix systems...) the second is: --disable-hipe which disables HiPE (High Performance Erlang) since on some systems it may crash... try not disabling it, do test, if in test Erlang Segfaults (repeat test five times) return to this step and reconfigure it without HiPE...: ./configure --enable-threads –disable-hipe Then you can compile it (if you’ve compiled it earlier, do make clean to remove old files): make and do some tests – you should get Erlang console: ./bin/erl if everything went right, you may install Erlang: make installsome more specific system infos are in Read Me file... Why I wrote this part of tutorial? Because they don't mention that on some Linux system when you have certain glibc and kernel, HiPE won't work and Erlang would segfault... while documentation says that it works on Linux and that it shouldn't be turned off... this probably would be fixed in some future releases... So you installed Erlang... see if it works by typing in command line: erl i don't like text only things... - or ESDL installation This will show you that Erlang is not only text-like environment for mathematical and old-school applications, we would install ESDL and run some test... Of course you must have Erlang running... and there is problem for Windows users – you would have troubles compiling ESDL – so its creators made for them pre compiled binary in one exe so like Erlang it can be installed very fast, but you wouldn't get any speed up that compilation normally gives. So for other operating system users – you should download source code and compile it yourself... you can download ESDL from [sourceForge]. There is info how to compile ESDL on Linux (Mac OS users should follow Read Me file, I cannot say anything about Mac, since I'm on Linux only): Just like above, unpack downloaded sources somewhere onto hard disk and change current directory to it... You should have SDL and OpenGL (also full GLU) to compile it... sometimes there are troubles locating GLU – some nVidia drivers for example keeps those libaries in non-standard place... you should locate your libGLU.so and libglut.so – they should be in /usr/lib (there is where all Erlang applications searches for it) but on my system they was in /usr/X11R6/lib and ESDL wasn't able to compile... if same or similar would happend to you, those symlinks fixed everything: ln -s /usr/X11R6/lib/libGLU.so /usr/lib/ ln -s /usr/X11R6/lib/libglut.so /usr/lib/ ldconfig now you can build ESDL – do: make and now there is time to do some tests , in shell type: cd testerl -pa ../ebin you should have Erlang shell opened and it should say something like: Erlang (BEAM) emulator version 5.4.5 [source] [threads:0] Eshell V5.4.5 (abort with ^G) so time to run test... type one or all of following (note the dot at the end, after every line press enter...): testsprite:go().testgl:go(). erldemo:go().testaudio:go(). testjoy:go(). If everything work – you may be happy and install everything: make install Now important thing about which many forgets... you should add path where ESDL is installed to your environment variables... In most cases ESDL would be installed in /usr/local/lib/erlang/lib/esdl-0.94.1025/ - if somewhere else, just modify method I would write there (remember that it is for Linux) – edit your /etc/profile file and add to it line: export ESDL_PATH="/usr/local/lib/erlang/lib/esdl-0.94.1025/"- After next restart you should have this added to your environment variables. If you don't want to restart now, add it manually, execute it in shell when you would need it... So you have now ESDL installed, and you saw that it can display graphics rather easy... Graphics in 2D and 3D would be discussed later... I want feel the speed but I'm on Windows... - or Some information So – Linux and Mac OS users can compile Erlang and ESDL and they gain performance... what can Windows users do about it? Besides... pre compiled versions are also somewhat compiled... how? So let me tell you – you must have a lot of software and patience that you probably wouldn't have – but if yes, I don't know what you are doing on Windows, when you can at least dual-boot into Windows/Linux... any way – You should have: CygWin (something like Linux emulator) with Make and other system tools SDL (Libraries similar to DirectX) MinGW (a C compiler) Sources like for Linux... ... and a lot of free time. When you install. Everything – your Erlang/ESDL should run faster than pre compiled versions, but you would for sure spot a lot of troubles compiling – if you want to have fast Erlang, get dual-boot with Linux... Erlang example: Wings 3D... - or Should users install Erlang? This is important question – if users should install Erlang and ESDL to watch/play/use product... if it would be so, Erlang would be forgotten very fast because users must have easier way of installing application so they won't get mad with it... great example is Wings 3D – pure Erlang/ESDL application that slowly reaches final version... I suggest to download it so you can see that Erlang is powerful and to feel the power under your fingers... of course – Wings runs from pre compiled binary and you don't need virtual machine installed, since it contains small version of it compiled and you don't even notice that someone have to install so many things to create it for you... What can I do with this virtual machine? - or Basic usage First of all you must start your Virtual Machine typing erl on *nix or running it from shortcut under Windows – You should see: Erlang (BEAM) emulator version 5.4.5 [source] [threads:0] Eshell V5.4.5 (abort with ^G) 1> First thing – I am able to run it... how can I quit it? So... to quit Erlang you must press Ctrl+C, then you should get: BREAK: (a)bort ©ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution and when you press "a" and then enter and Erlang would quit. So how this all works? First off all take a look at those numbers – these are line numbers – they doesn't refer to source code line numbers, since you don't write this code in Virtual Machine, but in any other text editor. Let's make something, type: 3+4.(note dot at end, after this press enter) You get 7... so this can be used as calculator... let's try something more complex: (2*11)/(3+4).As you see Erlang can do more... this is 22/7 which was used long time ago as PI number... but how can you get more exact PI? You have to type every time 3.14159? No - you can use math module – it has function pi which returns this value – try it: math:pi().Now try other function from module math: math:log(7.38909).You would get 2... if you know some elementary math, you would know why... As you see you can call any function from any module by typing: module:function(arguments). This is main Erlang calling structure which executes functions. So now we would define some functions – it would be most famous Erlang example – calculating factorial of natuarals... we would call our module that would contain this function – mymath – so create file mymath.erl (note that you must name your file same as module – this is important – without it Erlang would return error and you would search it some time...) - in this file type something like this: -module(mymath).-export([factorial/1]).factorial(1) -> 1;factorial(N) -> N * factorial(N-1).We would extend this example later, but now it is enough – save it so you wouldn't forget and let me explain it... first of all you named your module, remember to keep your module name same as file name but without .erl at end. Second you told Erlang that in this module is one function named factorial, containing one argument and only this function can be called from within this module (I wouldn't explain function now, since this one is easy... note the “;” at end of first function instance – this tells Erlang “this is not end of this function”). Let's get back to Erlang virtual machine (would call this eshell) and compile your module, do: c(mymath).You should get: {ok, mymath}(Remember to place file mymath.erl in directory from which you started Erlang so it can locate your file). Now it is time to see what we created Type: mymath:factorial(7).And as you see it is working... now let me show you how powerful function you wrote: mymath:factorial(10000).How about that? If you have enough RAM, you get result very fast This is of course externally mathematical example, but at the beginning you would meet almost only mathematical examples so you would get used to functional philosophy of Erlang. And I think this is enough for absolute beginning... with this series you would be able to learn Erlang step by step... soon you would be able to proof skills you gained there in project I'm going to start on AntiLost... You also would be able to take it as examples of how to make a game in Erlang since it would be highly documented... And this is end for now... Hope you liked it and would wait for next part, when we start playing with sequential way of Erlang. See Ya all next time... Giniu -------------------------- Thanks for corection of this tutorial goes like usual to Nelle... BIG THANKS...
-
Linux: Would It Be Worth Moving Toward Gcc 4.0?
Giniu replied to Giniu's topic in Websites and Web Designing
DAMN.... I paniced when saw info that there is troubles compiling kernel... don't think it is ready to be base for compilation of whole distribution... -
Yes... I agree - it's a great game... Also world is huge when you try to travel not with map, but by foot
-
hmm... 128 bits?? I was sleeping some time?? but what is sure... HT eat dust when you have 64-bit operating system on Athlon64/Opteron and compile your applications yourself...
-
yes, indeed... but this is hard work... take some movie: 1 minute = 60 seconds * 30 frames (29.9... you know...) gives you 1800 frames for one minute of movie... Cutting everything by hand or even with vector masks in horror... anyway - trick is nice... would probably use this technic if I would have to do something like this...
-
for myself I coose AMD since their POWER/PRICE is a lot better than Itel's... especialy now when you can get Athlon 64... I voted AMD...
-
Thats nice one realy interesting trick... but toying with transpariencies at movies are a lot easier with Cinelerra - where you don't have to do all that flashy-thing and from begining to end you work on avi's - but way do obtain this is same (just without conversion...) with Cinelerra it would be in simple, load two avi's to diferent layers, on top Layer draw selection, tell Cinelerra to cut what is behind it and leav what is inside... make sure to check some haracteristic points... and process movie to see results :PBut this is same as in Flash so idea in this tutorial is useful... PS.: there is mainly one thing - Cinelerra is free (you don't have Linux? Don't wory - you can use Live distribution so you would be able to "go-out" with your Cinlerra even wher you don't have Linux...) while Flash cost about 700$
-
Should I âBashâ or âbashâ? Or: âWriting scripts in GNU's Bourne Again Shellâ. For the begining â short story and what is what... In this tutorial I assume, that you don't have any basic knowledge, but you know Linux (or your other UNIX system) to understand what I'm talking about... Bash stands for Bourne Again Shell, it is child of Bourne Shell (sh), that was improved with elements of Korn Shell (ksh) and C Shell (csh) to gain power and new possibilities in programming and interactive use. It is quite easy while powerful... but what it is? What is shell? It is command line interpreter... and what is it? It is something in which you put code to execute... in UNIX command line interpreter is for example sh, bash, ksh, csh and many more... approximately about 30 more, in Windows command line interpreter is MS-DOS... we can say that... but it is quite primitive... anyway... So you knew what shell is, but now you also know that it is called shell... But what the heck is shell script? You heard many times that people was talking... âYou can write shell script that would do it for you...â What the... ? So... Let me explain â When you type commands in shell in interactive mode you give them one by one â seeing result after every command... so imagine that you have to do something twice... oh man borring... and when you have to repeat twenty command for hundred files in different directories? Mission impossible... so this is place when you have to write script â a file containing commands you would normally execute one by one, and when you run it, each command is run in right order so you can go get some coffee and relax while shell is doing hard job for you. Popular script file extensions are .sh (for UNIX-like systems, but you mainly don't need to give them any name â you can just make them executable and everything works just like it should) and .bat (for MS-DOS), so you probably saw few shell scripts in your life, but now you know the name... In this tutorial I wouldn't talk about MS-DOS' scripts, so from now on suppose only info about bash... Before I start â getting ready place to work... First of all, unpack your computer from box, look for some place on desk to put it on, then see if you have all wires... but serious â I want to talk about getting ready place to work... but on hard drive not on desk â scripts are files like others so you have to get some disk space where you write and test them... There are many schools â some people say, that best place for scripts is /bin directory... others â that itâs /usr/bin or /usr/local/bin... I think best place for scripts is /usr/scripts â that you would create â with symbolic links to /usr/local/bin so you can have all your scripts in one place and you can run them like they would be just in /usr/local/bin or even /bin â this is where I have them, and writing this tutorial I also assume that you would put them there, but of course you can modify this path and everything would work also great â this is you choice... If you decide to choose my way, create script directory: mkdir /usr/scriptI assume you know about permissions and choose them right â this is not place for this â If you want to know more about permissions refer to âDemystifying "chmod" - Part 1, & why viruses get so retarded on Linuxâ by microscopic^earthling. Let the game begin â very basics of bash scripting... So first of all â you have to know about variables. They are used exactly to what their name describes... they are used to store data... To use some variable you have to assign value to it... you just turned on your computer... you think that you haven't any variable in system? Then type in shell: echo $SHELLyou should see /bin/bashif not â execute /bin/bash and repeat this... Well so â there is one variable... maybe there are others? Type: echo $LONGNAMEecho $PWDand how is that? Yes â there are many more... you can see what variables are set by typing echo $ and pressing Tab key twice. So â now let's set some variable...: export MYVAR=âMy first variableâthen type: echo MYVARand you should see... MYVAR? Yes... because you don't have to invoke text MYVAR, but refer to value stored in MYVAR... now type: echo $MYVARuff... now it is working So now you see how can variables be used... in Scripts declaration are more easy, you have only to write: MYVAR=âMy frist variableâBut usage is same, you must refer to it by adding $ at the beginning... So Let's write some easy and useless script... Create text file in /usr/script of desired name ending with .sh, then make it executable, then edit it with your favourite text editor and put into it something like this (don't worry you don't know everything yet... I would explain it in a moment, just remember to put only empty line at end of file): #!/bin/bash# Now set some variable...:MYVAR=âmy first scriptâANOTHERONE=$MYVAR ':)'# and tell whole world about it, let's there be echo from this !!!echo this is $MYVAR.so... as you see this is useless program, but I will now explain it... first line... this strange #!/bin/bash... let's say that your default shell is sh or ksh â so scripts in bash shouldn't work for you? This line tells system âthis script is written in bash, execute it in bash interpreter â run /bin/bashâ. So â this is now clean what this mean... Then I left empty line â for scripts there doesn't mater how many empty lines you put into script... They are just for easy of read. Next one is strange again... I used hash like in first line, but you see that it must do something differ â and you are right â this is a comment â it also doesn't mater how many comments you put into your script... just when you read it after some time you know what do what... there is other comment in this example... I used in it echo â but it isn't consider as command echo â everything after â#â is ignored... Next line â I set variable... as you see I don't have to use export... you must be warn, that variables that are set in script doesn't exist without it â so you cannot use script to set system variables. But in next line you see, you can use variables to set variables â I used there single quotation to add smile to it... I used it because â()â are registered and reserved to gather code, so when you use it, it thinks you want to do is and not write ) - so I quoted it â they wouldn't be visible. But how can you quote ' ? Just double quote it â ' â and to quote â type ' â ' - easy, right? At last line I send text to default out â terminal (shell) and as you can see you can use variables and strings (text) in one line without any troubles... also adding dot at end doesn't matter â MYVAR is still interpreted as âMYVARâ, not as âMYVAR.â. And this is all... save it and run it... you should get: this is my first script So I'm keep going â expresions and I/O redirections... Right... so now let's make some arithmetics â now not in script but in shell, just like last time... Let's say sum 2 and 5... it should be 7 if I'm not wrong... type: expr 2 + 5as you can see + is divided from 2 and 5 by spaces... and the result is... who knows... 7... In bash you also can do multiplications /* (* cannot be used since it used as wildcard in file names), subtraction -, you can divide numbers / (integer results, floats result will be discussed later), count rest while dividing %. But there is one problem... you cannot send it to variable by typing: export SUM=expr 2 + 5since you would get error â also typing export SUM=âexpr 2 + 5âor export SUM='expr 2 + 5'won't work since you would get âexpr 2 + 5â not â7â... so if single and double quotation doesn't work what can be done? There is way â use backquote â ` â... try this: export SUM=`expr 2 + 5'echo $SUMand who knows... we get result! So there is explanation â using backquote sends result to variable... This can be assigned straight to variable, but if you want to use it without assigning result to variable, use $( command ) command, like: echo $( expr 2 + 5 )but it doesn't take care for new lines, try this: echo `ls`as you can see this is usesfull for short results processing. But what if you wan't to process some long text? Like files list above? You have to do some operations on it and as you know â you can make operations on files... so you can send output not ditectly to shell but to file... this works for any command... just use: command >> fileto send command results to file, or command << fileto send file to command using >> or << would add new strings at end of file, using < or > would overwrite file (and create new if there isn't one)... you can also send command results stright to command in two ways just like they would be usual files. Let's see some example that shows above two things... Let's write script that counts factorial from 9 to11 and send results to file. We would make it better when I would go to loops... But now let's get to work: #!/bin/bash#let's get first 9!FAC=`expr 2 \* 3 \* 4 \* 5 \* 6 \* 7 \* 8 \* 9`# send it to file creating new oneecho 9! = $FAC > factorial.result#count 10!FAC=`expr $FAC \* 10`#append it to fileecho 10! = $FAC >> factorial.result#do same as above for 11!FAC=`expr $FAC \* 11`echo 11! = $FAC >> factorial.resultwhen you would execute this script in directory where you executed it you have now file âfactorial.resultâ that contains desired results... quick and easy... now when you want to count factorial, just see what result it is... Something more â results processing... On UNIX-like systems there are many utilities that can be used to scripting, I won't talk about commands like cp, ls, rm, mv, chmod, su or cat since I think they was covered in prerequisites of this tutorial â this is very basic UNIX commands and without them you almost cannot use system... But there are few utilities about which I would write. First of them is wc: wc comes from âword countâ and it counts lines, words and characters in file... the result is formatted like: lines words characters file and can be invoked using wc filesecond utility I would mention is sort â it names says all, it sorts file, sending result to default stream (terminal) so you can redirect it to do example file. You can Invoke it by typing: sort filewhile you want to sort number, you probably want to use: sort -n fileto make 1000 larger that 2, you can also sort in inverse order, by typing: sort -r fileNow what if you want to change something in file? There is sed... Most common use of sed is: sed -e 's/FROM/TO/g' old_file > new_filethat form substitutes all FROM concurrencies to TO in old_file and saves modified file under name new_file... for example: sed -e 's/welcome/bye/g' welcome.sh > bye.shThere is also similar utility, but it can translate single letters, it is tr. Mainly tr is used to change one letter to another: tr 'letter1' 'letter2' < old_file > new_filechanges all letter1 ocurences to letter2 occurences in old_file and saves it under new_file. It can be used also with ranges, like in this example that converts lowercases to uppercases in file lower and saves it under file named upper: tr [a-b] [A-B] < lower > upperAnother useful utility for formatting and parsing is tail â it make file read from specified line to end of file, it can be invoked by: tail +line_number filetail +1 file doesn't make any difference than cat file, but tail +2 file don't show first line of file. Another thing that can be used to format output are pipes â thing that allow you to format it at time... There are many pipes but I would cover three of them. Pipes are used by using structure command | command, you can use multiple pipes â command | command | command... . First of commands mainly used in pipes is awk... awk is used to process column data, so you can display only one column of result, you can do this like that: ls -l | awk '{print $5}'not there are single quotes, not backquotes... mainly this looks like: command(s) | awk '{print $collumn_number}'of course awk have much more functionality, check man awk to see how powerful it is... Next utility is much smaller, but also useful for processing â it is head â it shows only n lines from file, for example: ls -l | head -3shows only first three lines of directory listing, mainly use of it looks like: command(s) | head -nso you can show only n lines from command's result. Next and last pipe I would talk about is grep â it is used to show only lines containing specified text, while using from shell it is very usefull while checking in checking pid of application to kill, then we use: ps x | grep application_nameand we get pid, then we are killing troublesome application. Mainly this pipe looks like: command(s) | grep textand shows only lines from result that contains text. Let's look at some example... first of all we would list files in current directory that are owned by root, then we would take their size, sort it and give in result size of largest and in separate block form second to fifth size. We write results to file, count characters and append it at end of file... #!/bin/bashecho larger file in $PWD directory have `ls -l | grep root | awk '{print $5}' | sort -n -r | head -1` bytes > sizeanalizer.resultsecho others have: >> sizeanalizer.resultsls -l | grep root | awk '{print $5}' | sort -n -r | tail +2 | head -5 >> sizeanalizer.resultsecho and maybe less... >> sizeanalizer.resultsSIZE=`wc sizeanalizer.results | awk '{print $3}'`echo -------------------------------------------------------- >> sizeanalizer.resultsecho >> sizeanalizer.resultsecho to display text above this line, $SIZE characters were used >> sizeanalizer.resultsit could be made easier, but the point is to demonstrate how these tools can be used... And what if... - Test constructs... As you see you can create now even complicated things... but what if you want to create file that exist or allow script to work only under exact circumstances? There you need to use if-else and case to do some test and steer script execution... right now our scripts were plain, now they got some depth and not always can execute same... it depends... but lets talk about test first... test string must be contained between [ ... ] or after test command â can be said this returns true or false, but don't shows them as strings. So lets see how test can be made (note spaces in [] - they are important !!!): STRING TESTS: [ stringA == stringB ] is true if strings A and B are equal [ stringA != stringB ] is true if strings A and B aren't equal [ -z string ] is true if string have zero length [ string ] or [ -n string ] is true if string has non-zero length [ stringA < stringB ] is true if string A is before string B (lexicographicaly) [ stringA > stringB ] is true if string A is after string B (lexicographicaly) NUMERIC TESTS: [ num1 -eq num2 ] stands for equal [ num1 -ne num2 ] stands for non-equal [ num1 -lt num2 ] stands for less than [ num1 -le num2 ] stands for less or equal [ num1 -gt num2 ] stands for greather than [ num1 -ge num2 ] stands for greater or equal FILE TESTS: [ -e file ] true if âfileâ exists [ -d file ] true if âfileâ exists and is directory [ -f file ] true if âfileâ exists and is regular file [ -L file ] true if âfileâ exists and is symbolic link [ -r file ] true if âfileâ exists and is readable [ -w file ] true if âfileâ exists and is writable [ -x file ] true if âfileâ exists and is executable [ -s file ] true if âfileâ exists and it's length is non-zero value [ -N file ] true if âfileâ have been modified since it was last read [ file1 -nt file2 ] true if âfile1â is newer than âfile2â [ file1 -ot file2 ] true if âfile1â is older than âfile2â OTHER TESTS: [ test1 -o test2 ] is true if true is any of tests [ test1 -a test2 ] is true if true are both of tests... true always true false always false warning, while using neasted tests don't use [ [ ... ] -o [ ... ] ] but only [ ... -o ... ], same for â-aâ!!! As you see there are many test and that aren't everything â they are only commonly used ones... So when you know how to make some test, let's go to if-else statement. Mainly if-else structure looks like this (consider tabs and spaces to make it easier to read): if expressionthen commandselse commandsfiwhen i write commands I mean any command and by expression some test or file execution... just let me show you some of possibilities: if [ $a == $b ]then echo a is equal to belse echo a isn't equal to bfithis is simplest way... it also can be written like that: if test $a == $bthen echo a is equal to belse echo a isn't equal to bfiif you want to see if some application returned value 0 (exited normally) use: if commandthen echo command exited normallyelse echo command exited abnormal, possible errors...fiof course commands can be another if...: if [ $a == $b ]then echo a is equal to belse if [ $a == $c ]then echo a is equal to c else echo a isn't equal to b or c fifithis can be written short: if [ $a == $b ]then echo a is equal to belif [ $a == $c ]then echo a is equal to celse echo a isn't equal to b or cfi As you see this can grow larger and larger every if-else... so what can we do about it? We can use case... It looks like this: case variable in value1 ) commands1;; value2 ) commands2;;... * ) default_commands;;esacso â when variable is equal to value1, commands1 will be executed, if variable is equal value2, commands2 will be executed... if there isn't suited value, default_cammands will be executed... There is some example: case $number in 1 ) echo number is one;; 2 ) echo number is two;; 3 ) echo number is three;; * ) echo I can count only to three;;esaccase values looks a little different than test... there is what can be used: strict value, like 1, 2, âsomethingâ logicaly added values, like value1 | value2 that stands for value1 or value2 range value, like [1-4] that stands for 1, 2, 3, 4 or [a-c] that stands for a, b, c just case allows us to create useful code fragments, like this: case $( arch ) in i386 ) echo 80386-based machine;; i486 ) echo 80486-based machine;; i586 ) echo Pentium-based machine;; i686 ) echo Pentium2+-based machine;; * ) echo Other type of machine;;esachow this would look using if-else? I can make you sure it would look longer... But what if you want to execute some fragment of code many times? You must use loops â loops that are allowed in bash are for and while, let me explain them... for should go first, it stands for âforeachâ and looks like: for variable in listdo commandsdonehow it works? It works like: variable = first in list commands variable = second in list commands ... so â what is list? This is easy... lists are any variables or wildcards â exactly, variables that looks like: variable=âvalueâhave one list element, but variable: variable=â value value value ...âhave many elements â and this is variable list... you can also create file wildcard list... that looks like: *.shthat contains all file names ending with .sh in current directory, or /usr/locale/games/mygame/*my*.dat?that contains all filenames that contains my and ends with .dat1, .dat2, .data or .dat^, but not .dat or .dat10 in directory /usr/locale/games/mygame Let me show you some example of for usage: LIST=".c .cpp .h"for EXTENSION in $LISTdo for FILE in *$EXTENSION do echo $FILE donedonethat would list all files ending for .c, .cpp and .h in current directory, so you see for is very powerful, but it can't be executed exact times if we don't know the list or if we don't need to use any list... and there with help comes while loop: while test_expressiondo commandsdonetest expressions can be similar to if-else, but mainly there are used string and number tests, files tests are rather useless in this command... There is part simple example that counts from 1 to 100: COUNTER=1while [ $COUNTER -le 100 ]do echo $COUNTER COUNTER=`expr $COUNTER + 1`doneEvery loop (for and while) can be stopped at any moment if it executes break command it goes behind loop. There is example of using break: while truedo echo you think this would be looping infinite? breakdoneecho WRONG ':)'Now I would give you some example of use what we learned till now... I won't talk what it does, you should now what, if not, get back to earlier parts... #!/bin/bashEXTENSIONS=".tex .abc"DIRECTORIES="design flash"if [ -e /tmp/countertemp ]; then echo "delete /tmp/countertemp to continue" exit 1fimkdir /tmp/countertempCOUNTERALL="0"COUNTER="1"LINESALL="0"for DIRECTORY in $DIRECTORIESdo for EXTENSION in $EXTENSIONS do COUNTERALL=`expr $COUNTERALL + 1` find $DIRECTORY -name *$EXTENSION -fprint /tmp/countertemp/_"$COUNTERALL"_.files donedonewhile [ $COUNTER -le $COUNTERALL ]do FILES="/tmp/countertemp/_"$COUNTER"_.files" LINES=$(wc "$FILES"|awk '{print $1}') LINE_NUMBER="1" while [ $LINE_NUMBER -le $LINES ] do FILENOW=$(tail +$LINE_NUMBER "$FILES"|head -1) LINENOW=$(wc "$FILENOW"|awk '{print $1}') LINESALL=`expr $LINESALL + $LINENOW` LINE_NUMBER=`expr $LINE_NUMBER + 1` done COUNTER=`expr $COUNTER + 1`doneecho $LINESALLrm -r /tmp/countertemp A little more advanced thing for the end â read, bc, arguments, exit, functions... This is almost everything â there are few small things left first of all â a float operations... this can be silly when you try to count percentage of something and get result 99/100=0 since 0.99 is taken down to 0 â so as you see float operations are required if you want to create some usefully counters... there is info how you can use them. I would only tell how to divide two variables, since other operations are similar...: echo "scale=5; $A / $B" | bcthis would divide A by B and would show 5 places... This looks so strange, because bash can store only integer values, so floats are stored as string and we have to do some conversions... but it works... Other thing I would mention at end are command line arguments so you can call you script not by: commandbut command option1 oprion2 option3 ...command line arguments can be accessed very easy â just use: $0 gives you command name that was executed to run script (without arguments) $1 stands for first argument $2 stands for second argument $# gives you number of arguments $* gives you all arguments as list they are considered usual variables, so you can for example do: echo there are $# command line arguments...So you know how to use command line arguments... was easy, right? Probably you also want to communicate with user in other way â let user type something on keyboard and store it under variable... this is as easy as say â just type in script: read VARIABLEecho $VARIABLEand you would see how it works... Ok... so we have that... and other thing... if your script executed other script you probably want to know if itâs succeed... there with help comes exit status... Just add to end of file exit with status number (0 means everything went ok, number form 1 to 255 means error) and you would know what happened to script... for example in scriptA executed from scriptB there is: if [ -e config ]then exit 1fi...exit 0and in scriptB we have: if scriptAthen echo config createdelse echo error ocured â config file present...fiAnd last thing that left to make you skilled shell programmer â functions... why use them? To make your script clean and easy to read, to not write same thing few times, there are many âbecauseâ so there is how you can define function: somefunction () { echo Argument number 1 $1 echo Argument number 2 $2}then you can call it by typing: somefunction arg1 arg2Oh man â really long tutorial, don't you think? But say... you can now write almost all scripts that you may want! Wasn't it worth to spend some time and read it? Any way â that is it â if you have some question just ask in this topic and I for sure would answer it... If you would find error (I'm just human...) also post it there I would check it again and PM moderator or admin to change it... Hope you liked it Regards Giniu ------------------------------------- PS.: If there is such need I can write another tutorial â essential Linux commands in which I would cover all topics that I said you have to start with it like using of commands like cp, mv, rm and basic Linux usage like changing mode to console and so on... everything that would fill the hole in wisdom... I would be happy to take a part in filling it Also if I made some mistake - just post fixed example/information so moderators/admins would be able to join it into this tutorial with note who fixed it PPS.: Thanks to Nelle for checking language things - english isn't my primary language... keep this in mind...
-
heh.. same for me... as far as I know only main (cPanel and ftp) passwords are affected, since through I can get to ftp through users that I created earlier... Hope this would be fixed quick