This is an example of what a simple Arduino sketch looks like after being imported into Atmel Studio. Atmel Studio added the auto generated sections at the top. The rest is identical to the original Arduino code. If you expand the ArduinoCore project that was created and look in the src -> cor...
CSS
body {
counter-reset: item-counter; /* create the counter */
}
.item {
counter-increment: item-counter; /* increment the counter every time an element with class "item" is encountered */
}
.item-header:before {
content: counter(item-counter) ". "; /* print the v...
A basic User Schema:
var mongoose = require('mongoose');
var userSchema = new mongoose.Schema({
name: String,
password: String,
age: Number,
created: {type: Date, default: Date.now}
});
var User = mongoose.model('User', userSchema);
Schema Types.
Methods can be set on Schemas to help doing things related to that schema(s), and keeping them well organized.
userSchema.methods.normalize = function() {
this.name = this.name.toLowerCase();
};
Example usage:
erik = new User({
'name': 'Erik',
'password': 'pass'
});
erik.nor...
Often times you will see an exception
Anti forgery token is meant for user "" but the current user is "username"
This is because the Anti-Forgery token is also linked to the current logged-in user. This error appears when a user logs in but their token is still linked to bein...
In many other languages, if you run the following
(Java example)
if("asgdsrf" == 0) {
//do stuff
}
... you'll get an error.
You can't just go comparing strings to integers like that. In Python, this is a perfectly legal statement - it'll just resolve to False.
A common gotcha ...
We can optimize a simple xor function for only architectures that support unaligned reads/writes by creating two files that define the function and prefixing them with a build constraint (for an actual example of the xor code which is out of scope here, see crypto/cipher/xor.go in the standard libra...
char buf[8]; /* tiny buffer, easy to overflow */
printf("What is your name?\n");
scanf("%s", buf); /* WRONG */
scanf("%7s", buf); /* RIGHT */
If the user enters a string longer than 7 characters (- 1 for the null terminator), memory behind the buffer buf will be...
For example, if t1 is currently not an InnoDB table, this statement changes its storage engine to InnoDB:
ALTER TABLE t1 ENGINE = InnoDB;
If the table is already InnoDB, this will rebuild the table and its indexes and have an effect similar to OPTIMIZE TABLE. You may gain some disk space improv...
Thread synchronization can be accomplished using mutexes, among other synchronization primitives. There are several mutex types provided by the standard library, but the simplest is std::mutex. To lock a mutex, you construct a lock on it. The simplest lock type is std::lock_guard:
std::mutex m;
vo...
The PieChart class draws data in the form of circle which is divided into slices. Every slice represents a percentage (part) for a particular value.
The pie chart data is wrapped in PieChart.Data objects. Each PieChart.Data object has two fields: the name of the pie slice and its corresponding valu...
The try { ... } catch ( ... ) { ... } control structure is used for handling Exceptions.
String age_input = "abc";
try {
int age = Integer.parseInt(age_input);
if (age >= 18) {
System.out.println("You can vote!");
} else {
System.out.println(...
Three methods are provided that offer the ability to strip leading and trailing characters from a string: str.strip, str.rstrip and str.lstrip. All three methods have the same signature and all three return a new string object with unwanted characters removed.
str.strip([chars])
str.strip acts o...
strpos can be understood as the number of bytes in the haystack before the first occurrence of the needle.
var_dump(strpos("haystack", "hay")); // int(0)
var_dump(strpos("haystack", "stack")); // int(3)
var_dump(strpos("haystack", "stackoverf...