If you are here to learn how to code in JavaScript, I highly suggest you DON'T use this as your only resource. Go to CodeAcademy or w3schools to get a more comprehensive guide to coding.
=== means equals to (useful in if statements)
!== means not equal to (again, useful in if statements)
Primitive Data Types:
Strings are created simply by opening up a pair of quotation marks (")
Numbers are integers or floats (such as 4 or 3.14)
Booleans are only true and false values (you simply write "true" or "false", without quotes)
% is the modulo operator. It prints the remainder of division operation.
confirm("Do you want to continue?");
Will display a confirm dialogue box. Returns a true or false.
alert("Something went wrong");
Only displays a dialogue box (use if you do not care about user input)
prompt("Enter in your name:");
Will display a dialogue box with text input. Returns the input as a string.
console.log("This message will be printed to your console (not the HTML page)");
Prints a message to the JavaScript console (this is usually found on a developer dashboard in browsers)
"This is a string".length;
Returns the character length of a string
"This is a string".substring(x, y);
Print out the portion of the string, with 'x' the character to start cutting from and 'y' the final character
var name = "String";
Assigning a variable (in this case a string)
"This is a String".match(/string/i)
This is string pattern matching, or Regular Expressions. Please see elsewhere how to use Regular expressions
var newArray = ["item 1", "item 2"];
Assiging an array of items.
var newFunction = function(variable) { return variable; };
Declaring a new function called newFunction, which can be called as newFunction("String")
var newObject = { key: "value", key2: 10, key3: function(value){ return value; } };
Declares a new object called newObject, with three properties.
var testObject = new newObject; testObject.key;
Declaring a new testObject of type newObject, and accessing the 'key' property
if (true) { return "True"; } else { return "False"; }
An "IF" conditional statement (with optional "ELSE")
for (var i = 0; i < condition; i++) { condition--; }
A "FOR" loop statement, with increment and decrement operators
switch (name) { case "value": return name; break; default: return false; }
A "SWITCH" or "CASE" statement.
while (value < 5) { value++; }
A "WHILE" loop.
try { arbitraryFunction(); } catch (err) { alert(err) }
A "try-catch" block.
throw "This is an error message";
An error thrown that is meant to be caught by a try-catch block. This just throws a simple string.
Math Object constants
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
Math.round(4.13);
Rounds the number to the nearest integer (in this example it will output 4)
Math.random()
Output a pseudo-random number between 0 and 1
document.getElementById("id");
Returns the HTML DOM element that matches the given id string
document.getElementsByClassname("class");
Returns the array of HTML DOM elements that matches the given class string
document.getElementById("id").innerHTML;
Gets (or sets) the HTML that is in between the element tag (make sure you note the capitalisation)
document.createElement("name");
Creates an DOM element (but it is not attached automatically!)
This blog is a knowledge dump of all the technical information floating around in my head. It deals with anything involving software, hardware, gadgets, and technology.
Feb 27, 2014
Jan 7, 2014
Notes from a Google Entreprenuer Day
These are notes I had lying around from a Google Entrepreneur Day.
- Small teams, Flat structure. Adaptibility. Agile, flexible, high sharing of data.
- Meritocracy and Transparency. Helps make passionate people.
- Execution. Experiment often, fail quickly. Testing and Auditing. Reward risk, do not punish failure.
- Collect and aggregate usage data. Data should not lie, and it will keep you honest.
- 3 A's of entrepreneurship:
- Audit Data and yourself.
- Admit when things are not working.
- Adapt in order to survive.
Understand your user
- Australia has the highest internet penetration. Best place to actually test. South Korea, UK and US are other penetration markets.
- Trends: Mobility, Video, Social, Cloud.
- Consumerism of IT. Take Consumer technology (phones, tablets, etc) into the business.
BigQuery
- Big Data is "When the cost of throwing away data becomes higher than technology used to store it"
- Batch-based solutions were not fast enough (for data-driven decision making)
- Accessed via RESTful API. Make it into a service.
- Suitable for aggregation and predictions.
Go
- Small language
- Simple type system
- Fast runtime properties
- Native concurrency support
- Fast development workflow
- Comprehensive standard library
- Standard library includes JSON, XML, net, SQL database and command line flags
Lean platforms for lean start-ups
- You are not the only one working on it. You do not always have a great idea.
- Steps:
- Start small, start fast
- Learn like a scientist. Rigorous, precise, learn from failure.
- Minimise friction to ship
- Advatange is that a start-up can focus on markets no-one cares about.
- Move fast and break things
Jan 6, 2014
Notes for Think Again: How to reason and argue (Sharpen Edges & Organise Parts)
These are my course notes for the Coursera course "Think Again" by Walter Sinnott-Armstrong at Duke University and Ram Neta at University of North Carolina.
This follows on from my earlier notes. And these.
This follows on from my earlier notes. And these.
Sharpen Edges
- We should seek adequate precision and adequate clarity, because absolute or perfect precision and/or clarity is futile and endless.
- When clarifying a claim, do not claim more than the speaker has to claim. ALWAYS CHOOSE THE MORE CHARITABLE OPTION.
- Clarification happens better when you are working with smaller premises (without distortion).
- Dependent clauses: These are premises that are dependent on another premise (usually given to help support our assertions). However, it depends on context on whether you break up dependent clauses into it's own premise.
- Dependent clauses are usually marked by that, which and who.
Organise Parts
- Liner structure:
Premise 1 leads to conclusion 2, which is a premise for conclusion 3... etc
1 -> 2 -> 3 - Branching structure:
Each premise given can independently support the conclusion, Missing one premise will not diminish the argument.
3 <- 1
^
|
2 - Joint structure:
Premises work togetherto provide support for the conclusion, and neither premise alone is sufficient for the conclusion.
1 + 2
______
3
Nov 30, 2013
Debian and XFCE: Print Screen Key
Print Screen Key
To enable the print screen key, just head on to Application Menu > Settings > Keyboard and click on the Application Shortcuts tab.Add a new command and in the text box enter in the following:
xfce4-screenshooter -fHit Ok, and the next dialogue will require you to enter in the key (or key combination) that will trigger this command (in this case, we will press the 'Prt Scr' key).
References:
Nov 29, 2013
Notes for Think Again: How to reason and argue (Lectures 3 Validity and Soundness)
These are my course notes for the Coursera course "Think Again" by Walter Sinnott-Armstrong at Duke University and Ram Neta at University of North Carolina.
This follows on from my earlier notes.
There are 2 main reasons for arguments to go wrong:
Remember the relation between premises and conclusions.
The rule for validity is:
This test helps us determine if the premises actually support the conclusion. Another way to look at it is that an argument is valid if and only if whenever its conclusion is false, at least one premise must also be false.
A valid argument is not:
An argument is sound if and only if:
If a deductive argument is not sound, then it is not a good argument (because a deductive argument is trying to be valid, with the conclusion following from it's premises).
Excess verbiage includes:
This follows on from my earlier notes.
VALIDITY
Remember that arguments consist of premises and conclusions, and these are supposed to be related in a good argument. We need some standards for evaluating arguments (so we can deconstruct, reconstruct and create our own). Two standards for evaluating arguments are 'Valid' and 'Sound'.There are 2 main reasons for arguments to go wrong:
- One or more premises are wrong or false
- The premises do not provide a good reason for the conclusion
Remember the relation between premises and conclusions.
- DEDUCTIVE: Conclusion follows from the premises. Trying to be valid.
- INDUCTIVE: Argument is not supposed to be valid. Conclusion does not follow from premises.
The rule for validity is:
An argument is valid if and only if it is not possible that both all of its premises are true and its conclusion is falseThis means that there can be no way both premises come out true when the conclusion is false. This stands if you assume that the conclusion is false and then test the premises; if they still remain true while the conclusion is asserted false, then it is NOT a valid argument.
This test helps us determine if the premises actually support the conclusion. Another way to look at it is that an argument is valid if and only if whenever its conclusion is false, at least one premise must also be false.
A valid argument is not:
- necessarily good. An argument can be valid but be no good at justifying or explaining the conclusion
- dependent on whether the premises and the conclusion are actually true. It is only dependent on what is possible.
SOUNDNESS
A sound argument is one where the conclusion must be true.An argument is sound if and only if:
- all of its premises are true
- it is valid
If a deductive argument is not sound, then it is not a good argument (because a deductive argument is trying to be valid, with the conclusion following from it's premises).
BASICS OF RECONSTRUCTION
The goal of reconstruction is to put an argument in a form in which we can easily and accurately assess it in as fair a manner as possible.- Do a close analysis
- Remove all excess verbiage
- List all explicit premises and conclusion in standard form
- Clarify where needed (Sharpen edges)
- Break up where possible without distortion
- Divide the argument into sub-arguments, and arrange them in order
- Assess whether each argument is valid
- Add suppressed premises where needed
- Check each premise for truth
- Qualify premiese to make them true where needed if possible
- Assess the argument.
Excess verbiage includes:
- People repeating themselves for rhetorical effect, stalling for time, or filling in the time
- Road markers -> help keep track of an argument (what we are talking about, and why). They don't offer anything additional to the argument. Includes changing topics.
- Tangents -> anecdotes and stories that make the argument interesting or memorable, but offer no reasons for the argument. They can also try to fool or distract you (red herring)
- Examples -> trying to highlight or bring to home the point of the argument. However, the example may just be an outlier. It can sometimes be used as a premise for the argument.
Nov 4, 2013
Debian: Installing gitolite
Tried setting up gitolite in Debian following my earlier guide with CentOS, but it didn't work out as well because there were a few steps missing (Debian doesn't create the gitolite user automatically). These are the modified steps:
- Install gitolite:
sudo apt-get install git git-core python-setuptools gitolite
- Add the gitolite user (this is the user that will host the git repositories and control access):
sudo useradd gitolite
- As the user who will be administrating the set-up (i.e. someone OTHER than the gitolite user), create a set of ssh keys and move them to where the gitolite user can access them:
ssh-keygencp ~/.ssh/id_rsa.pub /tmp/admin.pub
- Switch to the gitolite user:
sudo su - gitolite
- Run the set-up command:
gl-setup /tmp/admin.pub
- As the user who will be administrating the set-up, clone the repository
git clone gitolite@[ip address]:gitolite-admin.git
References:
Nov 3, 2013
Debian and XFCE Dual Monitors
Open up a terminal and type in xrandr. This will output the configuration of the currently connected monitors. Identify the names of your monitors (such as HDMI2, LCD1, VGA1, CRT2 or whatever). In this example we have two monitors, HDMI1 and HDMI2.
Now type in the desired layout:
To make this layout permanent, click on the Start menu > Settings > Session and Startup and then click on the Application Autostart tab. Add a new autostart item and then insert the xrandr command into the Command text field. Now if you restart your settings will be automatically loaded!
Now type in the desired layout:
xrandr --output HDMI2 --left-of HDMI1The monitors should now be showing your desired screen laytout. If not, play around until you have it.
To make this layout permanent, click on the Start menu > Settings > Session and Startup and then click on the Application Autostart tab. Add a new autostart item and then insert the xrandr command into the Command text field. Now if you restart your settings will be automatically loaded!
References
Subscribe to:
Posts (Atom)