diff options
-rw-r--r-- | bash.html.markdown | 13 | ||||
-rw-r--r-- | c.html.markdown | 5 | ||||
-rw-r--r-- | d.html.markdown | 50 | ||||
-rw-r--r-- | es-es/javascript-es.html.markdown | 4 | ||||
-rw-r--r-- | latex.html.markdown | 24 | ||||
-rw-r--r-- | python3.html.markdown | 4 | ||||
-rw-r--r-- | sass.html.markdown | 215 |
7 files changed, 277 insertions, 38 deletions
diff --git a/bash.html.markdown b/bash.html.markdown index 191f916a..211d2944 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -90,17 +90,26 @@ else echo "Your name is your username" fi +# NOTE: if $Name is empty, bash sees the above condition as: +if [ -ne $USER ] +# which is invalid syntax +# so the "safe" way to use potentially empty variables in bash is: +if [ "$Name" -ne $USER ] ... +# which, when $Name is empty, is seen by bash as: +if [ "" -ne $USER ] ... +# which works as expected + # There is also conditional execution echo "Always executed" || echo "Only executed if first command fails" echo "Always executed" && echo "Only executed if first command does NOT fail" # To use && and || with if statements, you need multiple pairs of square brackets: -if [ $Name == "Steve" ] && [ $Age -eq 15 ] +if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ] then echo "This will run if $Name is Steve AND $Age is 15." fi -if [ $Name == "Daniya" ] || [ $Name == "Zach" ] +if [ "$Name" == "Daniya" ] || [ "$Name" == "Zach" ] then echo "This will run if $Name is Daniya OR Zach." fi diff --git a/c.html.markdown b/c.html.markdown index fb77ca50..bfdf276c 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -54,6 +54,8 @@ int function_2(void); // Must declare a 'function prototype' before main() when functions occur after // your main() function. int add_two_ints(int x1, int x2); // function prototype +// although `int add_two_ints(int, int);` is also valid (no need to name the args), +// it is recommended to name arguments in the prototype as well for easier inspection // Your program's entry point is a function called // main with an integer return type. @@ -74,6 +76,9 @@ int main (int argc, char** argv) /////////////////////////////////////// // Types /////////////////////////////////////// + + // All variables MUST be declared at the top of the current block scope + // we declare them dynamically along the code for the sake of the tutorial // ints are usually 4 bytes int x_int = 0; diff --git a/d.html.markdown b/d.html.markdown index 88a83e41..80c1dc65 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -74,16 +74,18 @@ are passed to functions by value (i.e. copied) and classes are passed by referen we can use templates to parameterize all of these on both types and values! ```c -// Here, T is a type parameter. Think <T> from C++/C#/Java +// Here, 'T' is a type parameter. Think '<T>' from C++/C#/Java. struct LinkedList(T) { T data = null; - LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think <T> + + // Use '!' to instantiate a parameterized type. Again, think '<T>'. + LinkedList!(T)* next; } class BinTree(T) { T data = null; - // If there is only one template parameter, we can omit the parentheses + // If there is only one template parameter, we can omit the parentheses. BinTree!T left; BinTree!T right; } @@ -98,13 +100,11 @@ enum Day { Saturday, } -// Use alias to create abbreviations for types - +// Use alias to create abbreviations for types. alias IntList = LinkedList!int; alias NumTree = BinTree!double; // We can create function templates as well! - T max(T)(T a, T b) { if(a < b) return b; @@ -112,9 +112,8 @@ T max(T)(T a, T b) { return a; } -// Use the ref keyword to ensure pass by referece. -// That is, even if a and b are value types, they -// will always be passed by reference to swap +// Use the ref keyword to ensure pass by reference. That is, even if 'a' and 'b' +// are value types, they will always be passed by reference to 'swap()'. void swap(T)(ref T a, ref T b) { auto temp = a; @@ -122,13 +121,13 @@ void swap(T)(ref T a, ref T b) { b = temp; } -// With templates, we can also parameterize on values, not just types +// With templates, we can also parameterize on values, not just types. class Matrix(uint m, uint n, T = int) { T[m] rows; T[n] columns; } -auto mat = new Matrix!(3, 3); // We've defaulted type T to int +auto mat = new Matrix!(3, 3); // We've defaulted type 'T' to 'int'. ``` @@ -138,21 +137,20 @@ have the syntax of POD structures (`structure.x = 7`) with the semantics of getter and setter methods (`object.setX(7)`)! ```c -// Consider a class parameterized on a types T, U - +// Consider a class parameterized on types 'T' & 'U'. class MyClass(T, U) { T _data; U _other; - } -// And "getter" and "setter" methods like so +// And "getter" and "setter" methods like so: class MyClass(T, U) { T _data; U _other; - // Constructors are always named `this` + // Constructors are always named 'this'. this(T t, U u) { + // This will call the setter methods below. data = t; other = u; } @@ -175,16 +173,24 @@ class MyClass(T, U) { _other = u; } } -// And we use them in this manner +// And we use them in this manner: void main() { - auto mc = MyClass!(int, string); + auto mc = new MyClass!(int, string)(7, "seven"); + + // Import the 'stdio' module from the standard library for writing to + // console (imports can be local to a scope). + import std.stdio; + + // Call the getters to fetch the values. + writefln("Earlier: data = %d, str = %s", mc.data, mc.other); - mc.data = 7; - mc.other = "seven"; + // Call the setters to assign new values. + mc.data = 8; + mc.other = "eight"; - writeln(mc.data); - writeln(mc.other); + // Call the getters again to fetch the new values. + writefln("Later: data = %d, str = %s", mc.data, mc.other); } ``` diff --git a/es-es/javascript-es.html.markdown b/es-es/javascript-es.html.markdown index 036d7082..d475cf42 100644 --- a/es-es/javascript-es.html.markdown +++ b/es-es/javascript-es.html.markdown @@ -16,7 +16,7 @@ con Java para aplicaciones más complejas. Debido a su integracion estrecha con web y soporte por defecto de los navegadores modernos se ha vuelto mucho más común para front-end que Java. -JavaScript no sólo se limita a los navegadores web, aunque: Node.js, Un proyecto que proporciona un entorno de ejecución independiente para el motor V8 de Google Chrome, se está volviendo más y más popular. +Aunque JavaScript no sólo se limita a los navegadores web: Node.js, Un proyecto que proporciona un entorno de ejecución independiente para el motor V8 de Google Chrome, se está volviendo más y más popular. ¡La retroalimentación es bienvenida! Puedes encontrarme en: [@adambrenecki](https://twitter.com/adambrenecki), o @@ -124,7 +124,7 @@ undefined; // usado para indicar que un valor no está presente actualmente // (aunque undefined es un valor en sí mismo) // false, null, undefined, NaN, 0 y "" es false; todo lo demás es true. -// Note que 0 is false y "0" es true, a pesar de que 0 == "0". +// Note que 0 es false y "0" es true, a pesar de que 0 == "0". // Aunque 0 === "0" sí es false. /////////////////////////////////// diff --git a/latex.html.markdown b/latex.html.markdown index 146e8d45..e180e622 100644 --- a/latex.html.markdown +++ b/latex.html.markdown @@ -12,7 +12,7 @@ filename: learn-latex.tex % LaTeX is NOT a "What You See Is What You Get" word processing software like % MS Word, or OpenOffice Writer -% Every Latex command starts with a backslash (\) +% Every LaTeX command starts with a backslash (\) % LaTeX documents start with a defining the type of document it's compiling % Other document types include book, report, presentations, etc. @@ -45,7 +45,7 @@ filename: learn-latex.tex % but before the main sections of the body. % This command is available in the document classes article and report. \begin{abstract} - LaTex documentation written as LaTex! How novel and totally not my idea! + LaTeX documentation written as LaTeX! How novel and totally not my idea! \end{abstract} % Section commands are intuitive. @@ -63,8 +63,8 @@ I think we need another one Much better now. \label{subsec:pythagoras} -% By using the asterisk we can suppress Latex's inbuilt numbering. -% This works for other Latex commands as well. +% By using the asterisk we can suppress LaTeX's inbuilt numbering. +% This works for other LaTeX commands as well. \section*{This is an unnumbered section} However not all sections have to be numbered! @@ -74,7 +74,7 @@ a line \\ needs \\ to \\ break \\ you add \textbackslash\textbackslash to the source code. \\ \section{Lists} -Lists are one of the easiest things to create in Latex! I need to go shopping +Lists are one of the easiest things to create in LaTeX! I need to go shopping tomorrow, so let's make a grocery list. \begin{enumerate} % This creates an "enumerate" environment. % \item tells the enumerate to increment @@ -106,7 +106,7 @@ Here's how you state all y that belong to X, $\forall$ x $\in$ X. \\ % The opposite also holds true. Variable can also be rendered in math-mode. My favorite Greek letter is $\xi$. I also like $\beta$, $\gamma$ and $\sigma$. -I haven't found a Greek letter that yet that Latex doesn't know about! +I haven't found a Greek letter that yet that LaTeX doesn't know about! Operators are essential parts of a mathematical document: trigonometric functions ($\sin$, $\cos$, $\tan$), @@ -126,7 +126,7 @@ $^{10}/_{7}$ % \frac{numerator}{denominator} $\frac{n!}{k!(n - k)!}$ \\ -We can also insert equations in an "equation environment." +We can also insert equations in an "equation environment". % Display math with the equation 'environment' \begin{equation} % enters math-mode @@ -141,7 +141,7 @@ figures, equations, sections, etc. Summations and Integrals are written with sum and int commands: -% Some latex compilers will complain if there are blank lines +% Some LaTeX compilers will complain if there are blank lines % In an equation environment. \begin{equation} \sum_{i=0}^{5} f_{i} @@ -181,9 +181,9 @@ We can also insert Tables in the same way as figures. % \section{Hyperlinks} % Coming soon -\section{Getting Latex to not compile something (i,e, Source Code)} -Let's say we want to include some code into our Latex document, -we would then need Latex to not try and interpret that text and +\section{Getting LaTeX to not compile something (i.e. Source Code)} +Let's say we want to include some code into our LaTeX document, +we would then need LaTeX to not try and interpret that text and instead just print it to the document. We do this we a verbatim environment. @@ -198,7 +198,7 @@ environment. \section{Compiling} By now you're probably wondering how to compile this fabulous document -and look at the glorious glory that is a Latex pdf. +and look at the glorious glory that is a LaTeX pdf. (yes, this document actually does compiles). \\ Getting to the final document using LaTeX consists of the following steps: \begin{enumerate} diff --git a/python3.html.markdown b/python3.html.markdown index f3f4dd37..a1125c73 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -160,6 +160,10 @@ print("I'm Python. Nice to meet you!") # => I'm Python. Nice to meet you! # Use the optional argument end to change the end character. print("Hello, World", end="!") # => Hello, World! +# Simple way to get input data from console +input_string_var = input("Enter some data: ") # Returns the data as a string +# Note: In earlier versions of Python, input() method was named as raw_input() + # No need to declare variables before assigning to them. # Convention is to use lower_case_with_underscores some_var = 5 diff --git a/sass.html.markdown b/sass.html.markdown index 509aee9b..02bec47f 100644 --- a/sass.html.markdown +++ b/sass.html.markdown @@ -3,6 +3,7 @@ language: sass filename: learnsass.scss contributors: - ["Laura Kyle", "https://github.com/LauraNK"] + - ["Sean Corrales", "https://github.com/droidenator"] --- Sass is a CSS extension language that adds features such as variables, nesting, mixins and more. @@ -11,6 +12,7 @@ Sass (and other preprocessors, such as [Less](http://lesscss.org/)) help develop Sass has two different syntax options to choose from. SCSS, which has the same syntax as CSS but with the added features of Sass. Or Sass (the original syntax), which uses indentation rather than curly braces and semicolons. This tutorial is written using SCSS. +If you're already familiar with CSS3, you'll be able to pick up Sass relatively quickly. It does not provide any new styling options but rather the tools to write your CSS more efficiently and make maintenance much easier. ```scss @@ -121,6 +123,69 @@ div { +/*Functions +==============================*/ + + + +/* Sass provides functions that can be used to accomplish a variety of + tasks. Consider the following */ + +/* Functions can be invoked by using their name and passing in the + required arguments */ +body { + width: round(10.25px); +} + +.footer { + background-color: fade_out(#000000, 0.25) +} + +/* Compiles to: */ + +body { + width: 10px; +} + +.footer { + background-color: rgba(0, 0, 0, 0.75); +} + +/* You may also define your own functions. Functions are very similar to + mixins. When trying to choose between a function or a mixin, remember + that mixins are best for generating CSS while functions are better for + logic that might be used throughout your Sass code. The examples in + the Math Operators' section are ideal candidates for becoming a reusable + function. */ + +/* This function will take a target size and the parent size and calculate + and return the percentage */ + +@function calculate-percentage($target-size, $parent-size) { + @return $target-size / $parent-size * 100%; +} + +$main-content: calculate-percentage(600px, 960px); + +.main-content { + width: $main-content; +} + +.sidebar { + width: calculate-percentage(300px, 960px); +} + +/* Compiles to: */ + +.main-content { + width: 62.5%; +} + +.sidebar { + width: 31.25%; +} + + /*Extend (Inheritance) ==============================*/ @@ -150,6 +215,12 @@ div { border-color: #22df56; } +/* Extending a CSS statement is preferable to creating a mixin + because of the way it groups together the classes that all share + the same base styling. If this was done with a mixin, the width, + height, and border would be duplicated for each statement that + called the mixin. While it won't affect your workflow, it will + add unnecessary bloat to the files created by the Sass compiler. */ @@ -172,6 +243,7 @@ ul { /* '&' will be replaced by the parent selector. */ /* You can also nest pseudo-classes. */ /* Keep in mind that over-nesting will make your code less maintainable. +Best practices recommend going no more than 3 levels deep when nesting. For example: */ ul { @@ -212,6 +284,140 @@ ul li a { +/*Partials and Imports +==============================*/ + + + +/* Sass allows you to create partial files. This can help keep your Sass + code modularized. Partial files should begin with an '_', e.g. _reset.css. + Partials are not generated into CSS. */ + +/* Consider the following CSS which we'll put in a file called _reset.css */ + +html, +body, +ul, +ol { + margin: 0; + padding: 0; +} + +/* Sass offers @import which can be used to import partials into a file. + This differs from the traditional CSS @import statement which makes + another HTTP request to fetch the imported file. Sass takes the + imported file and combines it with the compiled code. */ + +@import 'reset'; + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + +/* Compiles to: */ + +html, body, ul, ol { + margin: 0; + padding: 0; +} + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + + + +/*Placeholder Selectors +==============================*/ + + + +/* Placeholders are useful when creating a CSS statement to extend. If you + wanted to create a CSS statement that was exclusively used with @extend, + you can do so using a placeholder. Placeholders begin with a '%' instead + of '.' or '#'. Placeholders will not appear in the compiled CSS. */ + +%content-window { + font-size: 14px; + padding: 10px; + color: #000; + border-radius: 4px; +} + +.message-window { + @extend %content-window; + background-color: #0000ff; +} + +/* Compiles to: */ + +.message-window { + font-size: 14px; + padding: 10px; + color: #000; + border-radius: 4px; +} + +.message-window { + background-color: #0000ff; +} + + + +/*Math Operations +==============================*/ + + + +/* Sass provides the following operators: +, -, *, /, and %. These can + be useful for calculating values directly in your Sass files instead + of using values that you've already calculated by hand. Below is an example + of a setting up a simple two column design. */ + +$content-area: 960px; +$main-content: 600px; +$sidebar-content: 300px; + +$main-size: $main-content / $content-area * 100%; +$sidebar-size: $sidebar-content / $content-area * 100%; +$gutter: 100% - ($main-size + $sidebar-size); + +body { + width: 100%; +} + +.main-content { + width: $main-size; +} + +.sidebar { + width: $sidebar-size; +} + +.gutter { + width: $gutter; +} + +/* Compiles to: */ + +body { + width: 100%; +} + +.main-content { + width: 62.5%; +} + +.sidebar { + width: 31.25%; +} + +.gutter { + width: 6.25%; +} + ``` @@ -226,6 +432,15 @@ Because people were constantly writing it as "SASS", the creator of the language If you want to play with Sass in your browser, check out [SassMeister](http://sassmeister.com/). You can use either syntax, just go into the settings and select either Sass or SCSS. + +## Compatibility + +Sass can be used in any project as long as you have a program to compile it +into CSS. You'll want to verify that the CSS you're using is compatible +with your target browsers. + +[QuirksMode CSS](http://www.quirksmode.org/css/) and [CanIUse](http://caniuse.com) are great resources for checking compatibility. + ## Further reading * [Official Documentation](http://sass-lang.com/documentation/file.SASS_REFERENCE.html) |