diff --git a/index.wiki b/index.wiki index 1999bc0..7c3513b 100644 --- a/index.wiki +++ b/index.wiki @@ -30,6 +30,7 @@ _Ideas.md and Classes.md are encrypted, so these links will not work_ * [[lang/C++|C++]] * [[lang/C-sharp|C#]] * [[lang/Python|Python]] +* [[lang/Bash|Bash]] * [[lang/HTML|HTML]] * [[lang/CSS|CSS]] * [[lang/Javascript|Javascript]] diff --git a/lang/Bash.wiki b/lang/Bash.wiki new file mode 100644 index 0000000..ded8761 --- /dev/null +++ b/lang/Bash.wiki @@ -0,0 +1,101 @@ += Bash = + +The shell itself + +== Common syntax == + +I tend to forget it sometimes lol + +=== Brackets === + +Remember '\[' is a program unto itself. Here are some common flags + +* -z + - empty string +* -n not + - empty string +* == aka -eq + - equal +* != aka -ne + - not equal +* -lt + - less than +* -gt + - greater than +* -ge + - greater than or equal +* ! + - not +* && + - and +* || + - or +* -e + - file exists +* -r + - is readable +* -h + - is symlink +* -d + - is directory +* -s + - has data in it +* -f + - is file +* -x + - is executable + +=== Variables === + +{{{ +var=55 +echo $var + }}} + +=== While === + +{{{ +while [ condition ]; do + echo "Hello world" +done + }}} + +=== Arays === + +{{{ +Fruits={'Apple','Banana','Orange'} + +Fruits[0]="Apple" +echo ${Fruits[0]} + +declare -A sounds +sounds[dog]="bark" +sounds[cow]="moo" +sounds[bird]="tweet" +sounds[wolf]="howl" + +echo ${sounds[dog]} # Dog's sound +echo ${sounds[@]} # All values +echo ${!sounds[@]} # All keys +echo ${#sounds[@]} # Number of elements +unset sounds[dog] # Delete dog + }}} + +=== Math === + +{{{ +$((a + 200)) #add 200 to a + }}} + + +=== Strings === + +{{{ +${FOO%suffix} #remove suffix from foo +${FOO#prefix} #remove prefix from foo +${FOO/from/to} #replace first instance of from with to +${FOO//from/to} #replace all instances of from with to +${#FOO} #length of foo + }}} + +[[index]] diff --git a/lang/C++.wiki b/lang/C++.wiki index e4d7c8b..f6d8a8c 100644 --- a/lang/C++.wiki +++ b/lang/C++.wiki @@ -14,4 +14,4 @@ drawbacks due to the Object abstraction. -[[../index]] +[[index]] diff --git a/lang/C-sharp.wiki b/lang/C-sharp.wiki index f8bb6cb..295e650 100644 --- a/lang/C-sharp.wiki +++ b/lang/C-sharp.wiki @@ -5,4 +5,4 @@ Purely object oriented language that relies on a JIT. Primary library is .NET -[[../index]] +[[index]] diff --git a/lang/C.wiki b/lang/C.wiki index fee5398..f9d1194 100644 --- a/lang/C.wiki +++ b/lang/C.wiki @@ -4,11 +4,11 @@ Systems language. One of the fastest langs around == Memory == -* [[bitwise_cast]] - Cast a type as another bit for bit +* [[bithacks]] - Wacky was to break memory == Also See == [[C++]] -[[../index]] +[[index]] diff --git a/lang/bithacks.wiki b/lang/bithacks.wiki new file mode 100644 index 0000000..7ddb316 --- /dev/null +++ b/lang/bithacks.wiki @@ -0,0 +1,68 @@ += Bithacks = + +Evil memory manipulation for speed + +== Bitwise_cast == + +This works for C/C++. Basically all you do it cast like this + +{{{C + float cast(int foo){ + return (* (float*)&foo); + } +}}} + +This is also known as the "evil floating point bit level hacking" from the +quake III fast inverse square root. Great for casting structs as memory for +hashing, or generally treating one set of bits as another type + +== Negating Floats == + +{{{ + float Negatefloat(float f){ + return cast_float_to_uint(f) ^ 0x80000000; + } + }}} + +== Fast log base 2 == + +IEE 754 is sci notification of a base 2 value, therefore this works very very +well. Breaks awfully with negtaives so be sure to check + +{{{ +const unsigned int OneAsInt = 0x3F800000; +const float ScaleUp = float(0x00800000); //2^23 +const float ScaleDown = 1.0f/ScaleUp; + +float Log2(float x){ + return float (cast_float_to_uint(f)-OneAsInt)*ScaleDown +} + }}} + +== Fast base 2 exponent == + +This is the opposite of the last one. Does 2^n fast + +{{{ +const unsigned int OneAsInt = 0x3F800000; +const float ScaleUp = float(0x00800000); //2^23 +const float ScaleDown = 1.0f/ScaleUp; + +float Log2(float x){ + return asfloat (cast_float_to_uint(f)*ScaleUp)+OneAsInt; +} + }}} + +== Not accurate square root == + +This doesnt do that well but its better really fast. Does a fast taking of the +float to the power of 0.5 + +{{{ +const unsigned int OneAsInt = 0x3F800000; +float sqrt(float x){ + return asfloat((asint(x)>>1)+(OneAsInt>>1)); +} + }}} + +[[index]] diff --git a/lang/bitwise_cast.wiki b/lang/bitwise_cast.wiki deleted file mode 100644 index a8a296f..0000000 --- a/lang/bitwise_cast.wiki +++ /dev/null @@ -1,16 +0,0 @@ -= Bitwise_cast = - -This works for C/C++. Basically all you do it cast like this - -{{{C - float cast(int foo){ - return (* (float*)&foo); - } -}}} - -This is also known as the "evil floating point bit level hacking" from the -quake III fast inverse square root. - -== Uses == - -* Casting structs for hashing diff --git a/lang/index.wiki b/lang/index.wiki new file mode 100644 index 0000000..749ac4d --- /dev/null +++ b/lang/index.wiki @@ -0,0 +1,20 @@ += Languages = + +== Sections == + +* [[C|C]] +* [[C++|C++]] +* [[C-sharp|C#]] +* [[Python|Python]] +* [[Bash|Bash]] +* [[HTML|HTML]] +* [[CSS|CSS]] +* [[Javascript|Javascript]] +* [[PHP|PHP]] +* [[Rust|Rust]] +* [[Go|Go]] +* [[sql|SQL]] + + + +[[../index]] diff --git a/sci/Measurment.wiki b/sci/Measurment.wiki index dbe8fd7..f8a8ea3 100644 --- a/sci/Measurment.wiki +++ b/sci/Measurment.wiki @@ -1,6 +1,6 @@ = Measurment = -This is also the introduction [[chapter]] +This is also the introduction chapter == Definitions ==