Description
We want to be able to write acceptance test for our Ember app that allow people to navigate to external websites as well as internal pages.
- Ability to ensure external redirect
- As of now, I have not found a way to test logic that involves external redirect (i.e. call to
window.location.replace ...
)
- As of now, I have not found a way to test logic that involves external redirect (i.e. call to
- Ability to ensure internal redirect
End Goal
// app/utils/build-transition.js
export default function buildTransition(route, input) {
if (isValidLink(input)) {
return { run: () => window.location.replace(input), valid: true };
} else if(isValidRoute(input)) {
return { run: () => route.transitionTo(input), valid: true };
} else {
return { run: () => { throw new Error(input) }, valid: false };
}
}
Step by step
- Create the application and call it
Local
# * **Local** allows people to find restaurants that offer local food and drinks(ex: yak or rice wine in Nepal)
# * User can view description and offered local refreshments of each found restaurant.
# * User can view menu on the restaurant's website `External transition`
# * For those restaurants that do not have a website, User can view menu on restaurant's page `Internal transition`
# we use node v8.4.0, npm 5.3.0, and ember-cli 2.14.2
ember new local && cd local
- Install dependancies
# we use ember-cli-mirage for backend simulation
ember install ember-cli-mirage
- Run the newly create app
ember serve
# you should see a running app by visiting http://localhost:4200
- Create necessary routes
# we use ember-cli-mirage for backend simulation
ember g route restaurants
ember g route restaurants/index # show list of found restaurants
ember g route restaurants/restaurant # show menu of the restaurant
- Create
build-transition
utility function
ember g util build-transition
- Add logic to the
build-transition
utility function
// our utility function allows us to
// 1. visit external url if user provides valid url
// 2. visit a page in our app if user provides a valid route's path name
// app/utils/build-transition.js
// ... check repo for implementation of isValidLink and isValidRoute
export default function buildTransition(route, input) {
if (isValidLink(input)) {
return { run: () => window.location.replace(input), valid: true };
} else if(isPresent(route) && isValidRoute(getOwner(route), input)) {
return { run: () => route.transitionTo(input), valid: true };
} else {
return { run: () => {throw new Error(input)}, valid: false };
}
}
- Write a unit test for
build-transition
function
// * NOTE that we are not calling run, but instead checking to see what would get executed if we call it.
// tests/unit/utils/build-transition.js
// ...
let MOCKApp;
module('Unit | Utility | build transition', {
before() {
MOCKApp = run(() => {
let application = Application.create();
application.IndexRoute = Route.extend({});
application.PageRoute = Route.extend({});
return application;
});
},
after() {
run(MOCKApp, 'destroy');
}
});
// ...
// tests/unit/utils/build-transition.js
// ...
test('it calls window location function for external links', function(assert) {
let link = 'https://example.com/menu.html';
let result = buildTransition(link);
assert.ok(result.valid);
assert.ok(!result.run.toString().includes('transitionTo'));
assert.ok(result.run.toString().includes('window.location'));
});
// ...
// tests/unit/utils/build-transition.js
// ...
test('it calls transitionTo function for internal links/routes', function(assert) {
let index = MOCKApp.__container__.lookup('route:index');
let link = 'page'; // this is the route name (not the path name)
let result = buildTransition(index, link);
assert.ok(result.valid);
assert.ok(!result.run.toString().includes('window.location'));
assert.ok(result.run.toString().includes('transitionTo'));
});
// ...
// tests/unit/utils/build-transition.js
// ...
test('it calls error function for invalid links/routes', function(assert) {
let link = 'invalid.route';
let result = buildTransition(link);
assert.ok(!result.valid);
assert.ok(!result.run.toString().includes('window.location'));
assert.ok(!result.run.toString().includes('transitionTo'));
assert.ok(result.run.toString().includes('error'));
});
// ...
- Run unit test for
build-transition
function
ember t -s -m 'Unit | Utility | build transition'
- Use the
build-transition
function insiderestaurants/index
route
// app/routes/restaurants/index.js
// ...
buildTransition(menuLink).run();
// ...
- Run the app to make sure all changes have taken effect
# do this if you have stopped your app
ember serve
# you should see a running app by visiting http://localhost:4200
Now you can do this!
Resources:
use cases
- Writing Acceptance test for Signup with Google feature


Ebean's Relational features
The goal of Ebean is not to hide the Relational Database. More than that the goal of Ebean is to
promote the use of Relational features when they make most sense.
The use of UpdateSql, CallableSql, FindByNative and MapBeans will sometimes
provide a simpler and more efficient solution that an ORM/Bean solution.
It is the intention for Ebean to provide both ORM and Relational features in the one persistence
layer. This gives the developers the ability to choose the approach that best solves their
needs. Whats more these features are all designed to work together in the same transaction.
Whether you use these features is up to you but hopefully you find them a useful way to get
the job done in a simple and transparent fashion.
|


What is BigO Notation, and what does it have to do with programming?
BigO Notation (or BigOh Notation) is used to measure the complexity of an algorithm in computer science.
In other words, it is used to describe the time that it takes to execute an algorithm if scaled to the worst case scenario. For example if we wanted to add<PHONE_NUMBER>4 +<PHONE_NUMBER>8 instead of 1 + 1, how much longer will it take?
Some things to know about BigO Notation:
- It is also used in mathematics, but we will focus on how it’s used in computer science and programming.
- It measures the worst-case scenario, not the average nor the best case.
- It only cares about the most significant part of the complexity. For example, n2 + 2n can be simplified to n2.
BigO Basics
These are the notations for different complexities and what it means:
O(1) - The algorithm will always finish in the same amount of time no matter how many times it is ran.
O(n) - This represents a linear relationship. The larger the input data, the longer it would take, proportionally.
O(n2) - An increase of twice the size of a data set would quadruple the size of the algorithm.
O(2N) - An increase of one step will double the size of the algorithm. This is exponential and an grow really quickly.
O(n!) - factorial or combinatorial complexity can also grow extremely fast. A good example would be the travelling salesman problem.
O(log N) - This describes a very common algorithm in programming, called the “binary search.” There’s actually a really good example for this: The telephone book. To find a name in the telephone book, you would open it in the middle, evaluate if the name is in the first or second half of the book, ignore the half that does not apply, essentially halving the size of the book with every iteration. So at first, an increase in data input will increase the performance of the algorithm significantly, but it eventually levels off.
What they look like:
This was just a basic overview of Big O Notation. I hope this will hold you over so that at least you can understand some idea of Big O Notation when you see it.
Resources:
- Plain English Explanation of Big O - Stack Overflow
- BigO Cheatsheet
- Big O Notation - Wikipedia
- Time Complexity - Wikipedia


As you may be aware there is a new version of OEM gateway called emonHub being developed and as part of that I have been exploring ways of receiving a wider range of data types and sizes from nodes over the RF network.
This method uses single letter "datacodes" either singularly to set a default type or in a chain to spell out the nodes data string format, much like the way we structure the data in an arduino sketch, a string of values held in a chain of types, (which until recently would of probably been all ints).
In theory there are 14 different data codes, but some are not supported by arduino and some are probably unnecessary (chart attached), in reality we could probably just use half of these.
This boosts the theoretical range to a potential minus 9.2 trillion'ish to plus 18.4 trillion'ish although testing beyond 14 digits of precision was not so precise, so +/- 100,000,000,000,000 (100 billion) is really the usable limit, in theory:-)
Please give it a try if can, it's very similar to OEM gateway in operation and the config file will be familiar but with a couple of additional fields. I've made a little script to install to pi with one line from the homedir.
git clone https://github.com/emonhub/dev-emonhub.git && dev-emonhub/install.sh
then the conf file needs to be edited, just add an api key for basic operation, then add node details to change data types.
nano /etc/emonhub/emonhub.conf
This is quite a complex subject so while I'm sort of expecting some formatting or calculation issues to surface once it's put to the test, but I'm also quietly confident, certainly with the more common ints and longs etc, not so sure about floats and doubles.
Attached is a screen dump of5 windows, the one on the left shows a part of the conf file, at the bottom of which you can see I have set a codes string of q, q, Q. From the bottom chart you can see that is 2 64bit signed Long Long's and a 64bit unsigned Long Long. Half way up on the left is a python script that posts a frame to socket 50011, that string is 25bytes long, (1 nodeid + 3x8bytes). When sent you can see the log tail in the bottom screen and the emonCMS input page at the top.
The second screen dump is exactly the same but a different string of 25bytes, showing the useful range within the 14 digit precision.
Although emonHub is not yet ready to release this is fully functional and any feedback from those of you willing to give it a test will help decide if it's useful. (please test fully before relying on it as it's very new)
The repo is at https://github.com/emonhub/emonhub/tree/development and you can visit https://docs.python.org/2/library/struct.html#format-characters for more info on the functions used.
Re: emonHub development - increase in scope of values over rfm network
Putting aside the theoretical possibilities, Narrowing the choice to just 7 datacodes would match the data types readily available in arduino (see attached chart), it is apparently possible to use larger values in arduino but that's for another day.
Most sketches use code like this to "package" the outgoing data (this example is from emonTxV3_RFM12B_DiscreteSampling.ino)
typedef struct { int power1, power2, power3, power4, Vrms, temp; } PayloadTX;
PayloadTX emontx;
in this package all the values are ints, this was standard and any software receiving the packet via an RFM network was designed to reconstruct any incoming "packages" as integers. To break the -32768 to 32,767 limits imposed by the ints, some later sketches use other data types, to my knowledge there are currently only 3 such sketches and they use longs to report watt hours. In these cases the data types are assigned for each value like this (example from emonTxV3_continuous_kwhtotals_noeeprom.ino)
typedef struct {
unsigned long msgNumber;
int realPower_CT1;
int realPower_CT2;
int realPower_CT3;
int realPower_CT4;
long wh_CT1;
long wh_CT2;
long wh_CT3;
long wh_CT4;
} Tx_struct;
Tx_struct tx_data;
These sketches break the int-only rules and are therefore not compatible with existing solutions, because the string of values can vary from sketch to sketch the recieving software needs to know that order to reconstruct the "package". And unless every node on a given network uses the same data structure, the receiving software must use the node id to identify which structure is being used
This data is given to emonHub in the form of a string of letters called datacodes for the example above, if that was for node 10 then we would have the following in the [nodes] section of the emonhub.conf file,
[[10]]
codes = L, h, h, h, h, l, l, l, l
this tell emon hub any "packages" from node 10 are ordered unsigned long, int, int, int, int, long, long, long, long and emonhub can perform checks to confirm the recieved package is a valid size and reconstruct the values correctly.
The previous all-int example (call it node 11) could be specified using
[[11]]
codes = h, h, h, h, h, h
which would provide an exact template for emonHub to use, so the size is set and can be checked or any node can have a "standard" datacode specified by using "code = " rather than "codes = " for example
[[11]]
code = h
would tell emonhub that node 11 is all ints but doesn't specify exactly how many, so emonhub will just check the package size is a multiple of the given datacodes size.
OR in actual fact in this all-int example would still get correctly handled with no entry at all as emonhubs "RFM2Pi" listener (receiver) has also been set to ints to catch any un specified nodes using standard int-only sketches using a "defaultdatacode = " setting in the RRM2Pi settings.
emonhub always looks for the more specific data, so any node "codes = " trumps node "code = " trumps "defaultdatacode = " , the default emonhub.conf has "defaultdatacode = h" set so that by default emonhub works exactly like OEM gateway and to that you can add specific node data.
The 3 non all-int sketches and their corresponding "codes" are
emonTxV3_continuous_kwhtotals.ino h, h, h, h, h, l, l, l, l
emonTxV3_continuous_kwhtotals_eeprom.ino h, h, h, h, h, l, l, l, l
emonTxV3_continuous_kwhtotals_noeeprom.ino L, h, h, h, h, l, l, l, l
emonhub can be used in place of oem_gateway or the rfm2pi module or raspberrypi_run.php. It also runs on windows (with some settings changed) if you just fancy seeing it in action,
Paul
Re: emonHub development - increase in scope of values over rfm network
In the interest of consistency I have changed the "code" and "codes" setting in the emonhub.conf to "datacode" and "datacodes" these terms are now used throughout the code and should really of been named like this from the outset.
Updating this dev version emonhub via git without updating emonhub.conf will cause a problem that is easily remedied by just editing emonhub.conf by prefixing "code =" and/or "codes =" with "data" eg
Paul
Re: emonHub development - increase in scope of values over rfm network
As emonHub has evolved some details have changed and this although this thread may still be useful to those wanting to know more about using datacodes some details may be alittle misleading, so for clarity here's a bit of an update.
The "defaultdatacode" setting is now also just called datacode, the term "datacode" is now consistently used throughout emonhub's settings.
The "datacode = h" is no longer required in the settings file to make the rfm2pi decode legacy "byte pair ints" as this is now hardcoded into emonhub's rfm2pi interface, it can however bee easily overridden by setting any single datacode in [[RFM2Pi]] [[[runtimesettings]]] or for a specific node using a single datacode or a string of datacodes in [nodes].
The accepted datacodes are currently limited to b, B, h, H, l, L and 0 (zero) just to simplify choice others can easily be 'switched' on if the need arises.
I hope this thread sheds a little light on what emonHub can do, without making it sound toooo complex. emonHub will function as a standard RFM2Pi interface by default, out of the box, without you even being aware this stuff exists. but if you need it it's there.
Paul
Re: emonHub development - increase in scope of values over rfm network
What would be really awesome is to include the option to have the emon hub post to PVoutput as well,
there are simple php scripts out there, but they don't help when the internet is unavailable temporarily and don't buffer the data, Having hte option to enable data posting to PVOutput would be awesome.


Threat to CM: probe on to track source of letter
by Staff ReporterThe Kerala Police have launched a probe to track the source of a letter which was sent in the name of Maoists to the Vadakara police with a threat to manhandle Chief Minister Pinarayi Vijayan.
The letter, which is said to have been posted from Kasaragod’s Cheruvathur, said retaliatory action would be taken against Mr. Vijayan to get justice for slain Maoists.
Enclosed with the handwritten letter were a few pro-Maoist leaflets threatening a sub-inspector at the Perambra police station. The writer, who identified himself as a leader of Maoists Urban Action Team, accused the sub-inspector of beating up people on various occasions and warned him too of retaliatory action.
Police sources said the letter would be handed over to a special investigation squad. A case was registered under Section 189 (threat of injury to public servant), 153 (provocation with intent to cause riot) and 506 (punishment for criminal intimidation) of the Indian Penal Code.


A Connecticut Yankee In King Arthur’s Court
by Mark Twain
A Connecticut Yankee In King Arthur’s Court is a satirical novel that depicts a contemporary American, Hank Morgan, who is transported to medieval England. In the court of the legendary King Arthur, Morgan uses his modern knowledge to face the trials and tribulations of the middle ages.
Source: Twain, M. (1890). A Connecticut Yankee In King Arthur’s Court. New York, NY: Charles L. Webster and Co.
- Preface and Introduction
- The preface is a disclaimer signed by the author. In the introduction/explanation, the stranger tells the narrator his story of being a yankee in Connecticut.
- Chapter 1: “Camelot”
- The Yankee and Clarence come upon a town of poorly-dressed peasants and a huge procession. They follow the procession to the castle. The Yankee assumes that the castle is an asylum.
- Chapter 2: “King Arthur’s Court”
- The Yankee meets Clarence. The Yankee tells Clarence about an eclipse that will occur within a few days. Clarence waits to see if it’s true. Clarence tells him about being a prisoner.
- Chapter 3: “Knights of the Table Round”
- The Yankee is brought to the Round Table. Prisoners present themselves to Guenever. Sir Kay tells about Launcelot stealing his armor, and Merlin puts everyone to sleep.
- Chapter 4: “Sir Dinadan the Humorist”
- Sir Dinidan is the first to awaken after Merlin’s tale and plays a joke to waken everyone.  Merlin suggests that they strip him and throw him in the dungeon.
- Chapter 5: “An Inspiration”
- Clarens tells the Yankee that he is to be burned at the stake. He asks Clarence to help him escape. Clarence denies him. The Yankee tells Clarence to tell the king that he’s a magician himself and he will ravage the kingdom if he is not let go. He makes it known that if he is put to death, he will block out the sun forever starting at the hour of his execution. Clarence moves the Yankee’s execution date up.
- Chapter 6: “The Eclipse”
- The Yankee resigns himself to die at the stake. As the monk chants over him, the eclipse begins. The king begs the Yankee to spare the sun. The Yankee gets the king to promise to make him his chief minister and executive and pay him a salary in return for the sun.
- Chapter 7: “Merlin’s Tower”
- The Yankee is dressed in fine clothes, but the people want another miracle. After Merlin speaks ill of the Yankee, he has Merlin banished to the dungeon. With Clarence to assist him, the Yankee attaches gunpower to the turrets. During a thunderstorm, the tower explodes.
- Chapter 8: “The Boss”
- The Yankee is comfortable in his new position, but has no title. He gains a title from the people, but is angered at the slavery and rule of the king. He likes the king, but does not respect him.
- Chapter 9: “The Tournament”
- The Yankee makes plans to start a newspaper. Because of a mix-up, Sir Sagramor challenges the Yankee to a battle. The king suggests to the Yankee that he should go out adventuring to gain reknown in order to make himself more worthy to fight Sir Sagamor.
- Chapter 10: “Beginnings of Civilization”
- The yankee declines the king’s suggestion. He starts a school system. He improves the mining system and begins to make the kingdom better and more functional. The Yankee trains Clarence to start a newspaper. the Yankee quadruples revenues and revamps tax methods, but the time comes for him to go questing.
- Chapter 11: “The Yankee in Search of Adventures”
- A maiden comes to the castle needing help rescuing 45 other women from three giant brothers. The king assigns it to the Yankee. The woman agrees to personally show him the way. He is dressed in his suit of armor and is on his way.
- Chapter 12: “Slow Torture”
- The Yankee is bothered by his armor and becomes irritable. The woman, Sandy, is annoying him with her constant inane babble.
- Chapter 13: “Freemen”
- The Yankee and his companions agree to stop for the night. They have no matches and no food. A storm comes and vermin crawl into the Yankee’s armor. He vows never to wear armor again. The Yankee invites some freemans to breakfast and chats with them on the subject of democracy.
- Chapter 14: “‘Defend Thee, Lord’”
- Seven men rush toward the Yankee, but are frightened away at the puffs of smoke coming from his pipe. Sandy makes the men swear to appear before the king and submit to the Yankee’s commands.
- Chapter 15: “Sandy’s Tale”
- Sandy speakes of Sir Gawain. The Yankee is bored and critcizes her storytelling.
- Chapter 16: “Morgan Le Fay”
- They reach a large castle and meet a knight who is depressed because he couldn’t convince anyone in the castle to take soap. They meet Morgan Le Fay. She sends the Yankee to the dungeon for complimenting King Arthur, her brother whom she hates. When Sandy reminds the court who the Yankee is, Morgan Le Fay passes it off as a joke.
- Chapter 17: “A Royal Banquet”
- Morgan Le Fay begs the Yankee to give them an exhibition of his powers. After prayer, a large dinner reception is held. An old woman interrupts the banquet to curse Le Fay for killing her grandson. Le Fay takes the Yankee to the dungeon to see a man being tortured on a rack. The Yankee asks to speak to the prisoner.
- Chapter 18: “In the Queen’s Dungeons”
- The prisoner confesses to the Yankee, but will not make it known to Le fay for fear of having his property taken away from his wife and child. the Yankee promises to send the prisoner to his colony for training. He promises to make Le Fay hang one day for her acts of violence. The Yankee reunites an imprisoned couple.
- Chapter 19: “Knight-Erranty as a Trade”
- Sandy continues her story.
- Chapter 20: “The Ogre’s Castle”
- They continue on their way and come to an ogre’s castle. He discovers that the castle is nothing but a pigsty watched over by swineherds. He buys the hogs and sets them free. Sandy insists that they are enchanted ladies. When the pigs are brought home, the Yankee begins to believe her.
- Chapter 21: “The Pilgrims”
- The Yankee and Sandy leave the house together. They join a procession of pilgrims going to the Valley of Holiness. The Yankee sees a procession of slaves and a young mother beaten. He vows to end slavery as soon as he can. They meet Sir Ozana Le Cure Hardy. The Yankee sends a message in Sir Ozana’s hat to Clarence.
- Chapter 22: “The Holy Fountain”
- The abbot is relieved to see the Yankee and insists he start at once. The Yankee declines saying that he is waiting for Merlin to finish. However, it’s a front as he is waiting for supplies from Camelot. The Yankee sees Merlin at the Holy Fountain (an ordinary well) trying spells. The Yankee goes down into the well and discovers the simple problem.
- Chapter 23: “Restoration of the Fountain”
- The Yankee has the area around the well cleared. He and his experts patch the well and put fireworks inside the well and prepare for a flashy miracle the next day. Merlin faints at the spectacle. The Yankee shows the monks how to work the pump.
- Chapter 24: “A Rival Magician”
- The abbot and the monks were eager to bathe. The Yankee finds a telephone office in an abandoned hermit’s cave. He calls Arthur and tells him that he will travel to Camelot. When he arrives, the Yankee is disappointed at the king’s choices for his army. The Yankee goes back to the monks and proves another magician a fraud. The Yankee checks on the progress of the king and makes arrangements for a large welcome.
- Chapter 25: “A Competitive Examination”
- The Yankee meets with the king’s officer examination board and helps the king choose his army. He makes a valid suggestion that the king readily accepts.
- Chapter 26: “The First Newspaper”
- The Yankee reads the first newspaper and is pleased, except for the tone of flippany of the writing. The monks are impressed with the paper and the Yankee is pleased.
- Chapter 27: “The Yankee and the King Travel Incognito”
- The Yankee and Arthur decide to wander through the countryside disguised as peasants. The king has a hard time acclimating to being a peasant.
- Chapter 28: “Drilling the King”
- The Yankee must constantly make up for the king’s blunders if they are to keep their disguises. The king tells the Yankee that he an even greater wizard than Merlin and the Yankee tells him that he can see into the future. The king quizzes him on the future of the world. The Yankee drills the king on how to act in a peasant dwelling and the king has a hard time adjusting to it, but finally catches on.
- Chapter 29: “The Smallpox Hut”
- The two come upon a hut with a woman dying of smallpox. The Yankee tries to convince the king to leave, but the king will not have it. Arthur brings the dying daughter to her mother and she proceeds to tell them about the cruelty of the church and the king and how they were excommunicated.
- Chapter 30: “The Tragedy of the Manor-House”
- The woman and her family members die at midnight. They hear the sons knocking and escape before they are spotted. They come upon people hanging from trees and see a mob of people. A storm comes and they escape. They find the manor of the house has been hanged and the family burned. The Yankee leads the mob to the three sons who escaped and killed the manor.
- Chapter 31: “Marco”
- The Yankee convinces the mob not to kill the men. They meet Marco. They run into a group of children who have strung up someone in imitating the adults. The Yankee invites the blacksmith to dinner.
- Chapter 32: “Dowley’s Humiliation”
- Dowley boasts of his success in financial matters and once the shop clerk has produced the bill (for the banquet) to the Yankee, the Yankee pays him in full and includes a sizeable tip. Dowley’s pride is wounded.
- Chapter 33: “Sixth Century Political Economy”
- The Yankee compares Dowley’s wages in his kingdom to those in Arthur’s kingdom. The guests are confused at the concept of real wages and the Yankee talks of trade unions. The Yankee talks about the cruelty of stoning and warns them that they may be stoned for breaking the law.
- Chapter 34: “The Yankee and the King Sold as Slaves”
- The Yankee and the king are taken for madmen and are chased by a mob of angry townspeople. When a nobleman saves them, they believe that they are free. They are taken to the square and, when they cannot provide proof that they are freemen, are sold as slaves.
- Chapter 35: “A Pitiful Incident”
- The slave dealer sees the king’s bravado and plans to beat the pride out of him. The king changes his mind and plans to abolish slavery. The Yankee hatches a plan of escape. They meet a young woman burned at the stake for being a witch and a young woman hanged. A priest promises to raise her baby as his own.
- Chapter 36: “An Encounter in the Dark”
- The Yankee sees Sandy who does not recognize him and he is relieved to see a newspaper. The dealer plans to sell the king and the Yankee to an old gentleman, but the Yankee plans an escape. When the escape goes terribly wrong, the Yankee is sent to prison.
- Chapter 37: “An Awful Predicament”
- The Yankee explains his situation as being and Earl’s property sent on an errand. The Yankee is immediately set free. He goes to the slave quarters and finds the master has been killed by the slaves. The slaves have all been condemned to death. The Yankee contacts Clarence and tells him to call Sir Launcelot to come and bring some knights. The Yankee is arrested as the missing slave and the hanging is arranged.
- Chapter 38: “Sir Launcelot and Knights to the Rescue”
- At the hanging, Arthur declares himself as king and he is met with jeers and ridicule. When the executioner comes to hang the king, the Yankee leaps up to save him and at that time, Launcelot rides in with his knights and Clarence, who has taught the knights to ride bicycles. The crowd makes their apologies to the king.
- Chapter 39: “The Yankee’s Fight with the Knights”
- The Yankee prepares for his battle with Sir Sagramor. They battle and the Yankee shoots him.
- Chapter 40: “Three Years Later”
- Three years later, the country is happy and prosperous. The Yankee plans to overthrow the Catholic Church and start universal suffrage after Arthur dies. The Yankee marries Sandy and they have a daughter who falls ill. They nurse her back to health. The Yankee introduces baseball to Camelot.
- Chapter 41: “The Interdict”
- When the Yankee and Sandy’s daughter, Hello, falls ill again, they spend weeks nursing her to health in France. The Yankee decides to travel back to England leaving his family in France. The Yankee arrives in Camelot to find it desolate.
- Chapter 42: “WAR!”
- Clarence reveals to the Yankee about Guenever’s affair with Launcelot, the war between Arthur and Launcelot, and the temporary rule of Mordred (who placed an interdict of the church placed on Camelot). Launcelot and Mordred killed each other in battle and the Church reversed the entire kingdom and brought it back to the way it was. The Yankee decrees that all of the old institutions of the church will be null. Clarence gathers boys for an army.
- Chapter 43: “The Battle of the Sand Belt”
- The Yankee sends word to all factories to evacuate all personnel for he plans to bomb the factories with secret mines. All of England is against the Yankee and plans to fight against him.
- Chapter 44: “A Postscript by Clarence”
- The Yankee is stabbed and Clarence falls sick. Merlin casts a spell on the Yankee and is electrocutred. Clarence and the boy hide the Yankee’s body and agree to write more in the manuscript.
- Final P.S. by M.T.
- The narrator finishes the manuscript at dawn and goes to see the stranger who is awakening from a dream. He talks of a king and modern inventions and being sent backward in time. The stranger dies.


Welcome ${FULL_NAME}!
You were authenticated via [${PROVIDER_NAME}].
Your authenticated Resource ID: ${AUTHENTICATED_RESOURCE_ID}
Resource mappings:
| Resource ID |
Provider name |
Unique user ID |
${RESOURCE_MAPPINGS}
The logout button only invalidates your session in this sample application, it does not log out you on the
OAuth2 server (${PROVIDER_NAME}).


--- title: Index permalink: / ---
Hello there! This is the BDD enviroument
for you to extend and test Luda.
Use cases are located in
the src/html
directory.
Find sass
and coffee
files in the src/sass
and src/coffee
directory.


--- layout: post title: "Nevada City Classic" external-url: http://images.velodramatic.com/nevadacity09/ ---
The full gallery of shots from Velodramatic in one of the best Flash slideshow presentations I’ve seen.


1. Preface¶
Chinese proverb
The palest ink is better than the best memory. – old Chinese proverb
1.1. About¶
1.1.1. About this note¶
This document is a summary of our valueable experiences in using Python
for Data Scientist
daily work. The PDF version can be downloaded from HERE.
You may download and distribute it. Please be aware, however, that the note contains typos as well as inaccurate or incorrect description.
In this repository, we try to use the detailed Data Scientist
related demo code and
examples to share some useful python tips for Data Scientist work. If you
find your work wasn’t cited in this note, please feel free to let me know.
Although we are by no means a python programming and Data Scientist expert, We decided that it would be useful for us to share what we learned about Python in the form of easy note with detailed example. We hope those notes will be a valuable tool for your studies.
The notes assume that the reader has a preliminary knowledge of python
programing, LaTex
and Linux
. And this document is generated automatically by using sphinx. More details can be found at [Georg2018].
1.1.2. About the authors¶
Wenqiang Feng
- Data Scientist and PhD in Mathematics
- University of Tennessee, Knoxville
- Webpage: http://web.utk.edu/~wfeng1
- Email<EMAIL_ADDRESS>Xu Gao
- Data Scientist/Quantitative Analyst and PhD in Statistics
- Statistics, University of California, Irvine
- Webpage: https://sites.google.com/view/xugao
- Email<EMAIL_ADDRESS><EMAIL_ADDRESS>Upendra Madam
- Senior Data Engineer
- Computer and Information Sciences
- University of Texas, Arlington
- Email<EMAIL_ADDRESS>Declaration
The work of Wenqiang Feng was supported by the IMA, while working at IMA. However, any opinion, finding, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the IMA, UTK, UCI, DST and Google.
1.2. Motivation for this note¶
No matter you like it or not, Python has been one of the most popular programming languages.
I have been using Python
for almost 4 years. Frankly speaking, I wasn’t impressed and attracted
by Python
at the first using. After starting working in industry, I have to use Python
. Graduately
I recognize the elegance of Python and use it as one of my main programming language. But I foud that:
- Most of the
Python
books or tutorials which emphasize on programming will overwhelme the green hand. - While most of the
Python
books or tutorials forData Scientist
orData Analysis
didn’t cover some essential skills from the engineer side.
So I want to keep some of my valuable tips which are heavily applied in my daily work.
1.3. Feedback and suggestions¶
Your comments and suggestions are highly appreciated. I am more than happy to receive corrections, suggestions or feedbacks through email (Wenqiang Feng<EMAIL_ADDRESS>XuGao<EMAIL_ADDRESS>for improvements.


{% for song in song_list %} {% if forloop.first %}
Contributed by {{ song.user_nickname }}
There are no songs yet


1 + 1
2 + 2
If you're new to jupyter notebooks, note that only the last line of a cell prints by default when you execute that cell and that you can suppress this output with a semicolon
1 + 1
2 + 2;
To get docs for a function you're not familiar with, precede it with a question mark. (This works in the terminal too!)
?println
Type ;
and then you can use shell commands. For example,
;ls
;pwd


Before Change
def _embed_code_links(app, gallery_conf, gallery_dir):
// Add resolvers for the packages for which we want to show links
working_dir = os.getcwd()
os.chdir(app.builder.srcdir)
doc_resolvers = {}
for this_module, url in gallery_conf["reference_url"].items():
try:
if url is None:
doc_resolvers[this_module] = SphinxDocLinkResolver(
app.builder.outdir,
gallery_dir,
relative=True)
else:
doc_resolvers[this_module] = SphinxDocLinkResolver(url,
gallery_dir)
except HTTPError as e:
print("The following HTTP Error has occurred:\n")
print(e.code)
except URLError as e:
print("\n...\n"
"Warning: Embedding the documentation hyperlinks requires "
"Internet access.\nPlease check your network connection.\n"
"Unable to continue embedding `{0}` links due to a URL "
"Error:\n".format(this_module))
print(e.args)
html_gallery_dir = os.path.abspath(os.path.join(app.builder.outdir,
gallery_dir))
// patterns for replacement
link_pattern = "%s"
orig_pattern = "%s"
period = "."
for dirpath, _, filenames in os.walk(html_gallery_dir):
for fname in filenames:
print("\tprocessing: %s" % fname)
full_fname = os.path.join(html_gallery_dir, dirpath, fname)
subpath = dirpath[len(html_gallery_dir) + 1:]
pickle_fname = os.path.join(gallery_dir, subpath,
fname[:-5] + "_codeobj.pickle")
if os.path.exists(pickle_fname):
// we have a pickle file with the objects to embed links for
with open(pickle_fname, "rb") as fid:
example_code_obj = pickle.load(fid)
fid.close()
str_repl = {}
// generate replacement strings with the links
for name, cobj in example_code_obj.items():
this_module = cobj["module"].split(".")[0]
if this_module not in doc_resolvers:
continue
try:
link = doc_resolvers[this_module].resolve(cobj,
full_fname)
except (HTTPError, URLError) as e:
print("The following error has occurred:\n")
print(repr(e))
continue
if link is not None:
parts = name.split(".")
name_html = period.join(orig_pattern % part
for part in parts)
str_repl[name_html] = link_pattern % (link, name_html)
// do the replacement in the html file
// ensure greediness
names = sorted(str_repl, key=len, reverse=True)
expr = re.compile(r"(?<!\.)\b" + // don"t follow . or word
"|".join(re.escape(name)
for name in names))
def substitute_link(match):
return str_repl[match.group()]
if len(str_repl) > 0:
with open(full_fname, "rb") as fid:
lines_in = fid.readlines()
with open(full_fname, "wb") as fid:
for line in lines_in:
line = line.decode("utf-8")
line = expr.sub(substitute_link, line)
fid.write(line.encode("utf-8"))
print("[done]")
os.chdir(working_dir)
def embed_code_links(app, exception):
Embed hyperlinks to documentation into example code
After Change
link = doc_resolvers[this_module].resolve(cobj,
full_fname)
except (HTTPError, URLError) as e:
if isinstance(e, HTTPError):
extra = e.code
else:
extra = e.reason
print("\t\tError resolving %s.%s: %r (%s)"
% (cobj["module"], cobj["name"], e, extra))
continue


i want to re-open this topic.
i think/hope that with bf3stats it could be possible to integrate the Vehicle Service Stars by bf3stats.com (like the Top X% by each vehicle and weapon).
i have made a picture how it could look:
http://temp.elchalarm.net/bblog-vehicle-servstar.jpg
The Text ("Fahrz.") next to "Service Stars" have to be replaced with "Classes" and "Vehicles", so you can change between Class-Service Stars and Vehicle Service Stars.
if we go with the mouse over the service stars we will get the black bubble like now with information how many % of the next Service Star we allready have.
-----------------------------------------------------------------------
an other point:
Could you reorganize the the buttons on the vehicle page?
currently they are organized like this:
AHA - AJA - AHS - AJF - MBT - AAV - IFV - VT - WSAA - WSAT - All
It would be better to organize / show them by Classes as by the Service Star. That means:
AHS - IFV - AHA - MTB - AAV - AJF - VT - WSAA - WSAT - All
in detail i mean, there are no differents between "Air Jet Attack" and "Air Jet Fighter".
-----------------------------------------------------------------------
Other point: you're writing "VT" and in the descripttion (bubble) its written "Transport Vehicle". shouldn't it be "TV" or "Vehicle Transport"?
Last Point: what does "WSAA" and "WSAT" mean? "W??? Stationary Anti Air" and "W??? Stationary Anti Transport"? Shoulnd't be written "WSAV" for "W??? Stationary Anti Vehicle"?
-----------------------------------------------------------------------
only a few points. the last section (with WSA...) is not so important... i have just thought a little bit about these words.


#include <db_cxx.h>int Db::fd(int *fdp);
The Db::fd method copies a file descriptor representative of the underlying database into the memory referenced by fdp. A file descriptor referencing the same file will be returned to all processes that call Db::open with the same file argument. This file descriptor may be safely used as an argument to the fcntl(2) and flock(2) locking functions. The file descriptor is not necessarily associated with any of the underlying files actually used by the access method.
The Db_fd function only supports a coarse-grained form of locking. Applications should use the lock manager where possible.
The Db::fd method either returns errno or throws an exception that encapsulates an errno on failure, and 0 on success.
The Db::fd method may fail and throw an exception for any of the errors specified for the following Berkeley DB and C library functions: DBmemp->pgin(3), DBmemp->pgout(3), abort(3), close(3), dbenv->db_paniccall(3), fcntl(3), fflush(3), fprintf(3), free(3), fsync(3), getenv(3), getpid(3), getuid(3), isdigit(3), DbLog::compare, DbLog::flush, lseek(3), malloc(3), memcpy(3), memset(3), open(3), pread(3), pwrite(3), qsort(3), read(3), realloc(3), sigfillset(3), sigprocmask(3), stat(3), strerror(3), strlen(3), unlink(3), vfprintf(3), vsnprintf(3), and write(3).


Projects --
Home page
Hangman
Start
Click the Start button to begin the game.
Click on letter to Guess
To win, guess all letters
To lose, guess incorrectly 10 times


Functions | |
| int | int_equal (void *location1, void *location2) |
| Compare the integer values pointed at by two pointers to determine if they are equal. | |
| int | int_compare (void *location1, void *location2) |
| Compare the integer values pointed at by two pointers. |
To find the difference between two values pointed at, use int_compare.
To find if two values pointed at are equal, use int_equal.
| int int_compare | ( | void * | location1, | |
| void * | location2 | |||
| ) |
Compare the integer values pointed at by two pointers.
| location1 | Pointer to the first value to compare. | |
| location2 | Pointer to the second value to compare. |
| int int_equal | ( | void * | location1, | |
| void * | location2 | |||
| ) |
Compare the integer values pointed at by two pointers to determine if they are equal.
| location1 | Pointer to the first value to compare. | |
| location2 | Pointer to the second value to compare. |


--- layout: post status: publish published: true title: Playing with Roslyn and VSIX author: display_name: Tomas Restrepo login: tomasr email<EMAIL_ADDRESS>url: http://winterdom.com/ author_login: tomasr author_email<EMAIL_ADDRESS>author_url: http://winterdom.com/ wordpress_id: 1495 wordpress_url: http://winterdom.com/?p=1495 date: '2014-11-11 02:52:51 +0000' date_gmt: '2014-11-11 02:52:51 +0000' categories: - Visual Studio tags: [] comments: [] ---
I have been playing a bit with the Roslyn APIs in Visual Studio "14". Since I am a big fan of VS editor extensions, my first attempt was building something simple: A Visual Studio tagger that would colorize uses of parameter variables and field variables in code:
The code is ugly as it is, and does not use the Roslyn Async API, which is something I'd like to look into later on. I'm also not entirely sure if there's a better way to build such a thing (Roslyn has it's own concept of classification, but not sure if that is extensible). It was fun, though!
Code can be found here


|
Mail Directory Dialog Box
|
Previous Top Next |
| · | To refresh the list click the Update button.
|
| · | To download the currently highlighted file, click the Download button.
|
| · | To erase the currently highlighted file, click the Erase button.
|
| · | To send the currently highlighted file to another user on CIX Forums, click the Send File button.
|
| · | To export the currently highlighted file to a CIX forum topic, click the Export button.
|
| · | To rename the currently highlighted file, click the Rename button.
|


UFC Sao Paulo post-fight bonuses: Oliveira dazzles with POTN knockout
by Stephie HaynesGinasio do Ibirapuera Paraíso in Sao Paulo, Brazil was home to a very mediocre night of fights. The card saw two (T)KOs, two submissions and eight decisions, including one split-decision and one split-draw.
The card was punctuated by lots of decisions, eight of them to be exact, with several being real slogs to watch. The main event was the biggest slog of all, a boring affair with not much action outside the fifth round where Blachowicz managed to score a flash knockdown on Jacare. Fans and media were not short on barbs when describing the bout and/or event as a whole:
Performances of the Night: Randy Brown, Ricardo Ramos. James Krause, and Charles Oliveira
Randy Brown (R2 triangle), Ricardo Ramos (R1 RNC). James Krause (R3 KO), and Charles Oliveira (R1 KO) were all victorious via stoppage and all four men would take home $50,000 bonuses for their efforts.
Fight of the Night: Zero. Zip. Zilch.
Tracy Cortez, Ariane Lipski, Douglas Silva de Andrade, Francisco Trinaldo, Wellington Turman, Andre Muniz, and Jan Blachowicz all notched decision victories tonight, while Paul Craig and Shogun battled to a split-draw, but none of these contests warranted a bonus in the eyes of the brass.
Announced Attendance: 10,344


Pop ups
Clicking on the links will show pop up view
Slide to left
Pop ups support includes different effects including sliding in from a specific direction
Be sure to export as a single page application and include the pop up in the artboards to export (select artboards)
Slide to right
Slide to top
Slide to bottom
Dissolve
Centered
Horizontal Centered
Vertical Centered
Normal
With Close Button
Anchored right
Anchored horizontal bottom
Anchored bottom


Jose Mourinho predicts where Tottenham will finish this season
Jose Mourinho says he will work game by game to help Tottenham to climb the Premier League table
by The Sport Review staffJose Mourinho has told Tottenham Hotspur fans that he is expecting to see the club climb the Premier League table before the season is out.
Mourinho is currently getting used to life at the north London club after having been brought in as Mauricio Pochettino’s successor on Wednesday.
Spurs opted to sack Pochettino and his coaching staff on Tuesday night after a poor start to the season left the north London side languishing in 14th place in the Premier League table.
Mourinho has been tasked with steering the Lilywhites back up the Premier League table as they look to try and at least break back into the top four.
First up for Mourinho and his Spurs team is a London derby clash against West Ham United at the London Stadium on Saturday lunchtime.
And Mourinho has told Spurs fans that he will take it game by game as the Lilywhites look to break back into the top four.
Speaking in an interview quoted by Sky Sports, Mourinho said: “In relation to the Premier League, I think we know where we are and we know that we don’t belong there.
“We should just play match after match, the next match we want to win and that’s the same about the next, and the next, and the next until the last.
“At the end of the season we will see where we are but I know that we are going to be in a different position than we are now.
“I look forward to the challenge, to the responsibility to bring happiness to everyone that loves the club.”
Spurs will then return to Champions League action on Tuesday night when they host Olympiakos in the group stage at their home ground.
After that, they will host Bournemouth in the Premier League.


Generates a test case for the selected class.
The generated class contains skeleton test methods for the selected public methods.


This challenge has 10 problems. The learn-ocaml system will mark your solutions out of 100pts but we will be grandting a 1.25 scale curve (i.e. we will 80% completion as full marks). No bonus points for achieving above 80% will be awarded unforntunately.
Important Note 1: The number of points assigned to a problem is no indication of the it's difficulty.val identity : 'a -> 'a = <fun>
val reverse : 'a list -> 'a list = <fun>
val palindrome : 'a list -> bool = <fun>
val squeeze : 'a list -> 'a list = <fun>Here is an example execution:
# squeeze [1;2;2;2;3;3;2;4;4];; - : int list = [1; 2; 3; 2; 4]
val sprinkle : 'a list -> ('a list * 'a list) list = <fun>Here are some examples:
# sprinkle [1;2;3;4];; - : (int list * int list) list = [([1; 2; 3; 4], []); ([1; 2; 3], [4]); ([1; 2; 4], [3]); ([1; 2], [3; 4]); ([1; 3; 4], [2]); ([1; 3], [2; 4]); ([1; 4], [2; 3]); ([1], [2; 3; 4]); ([2; 3; 4], [1]); ([2; 3], [1; 4]); ([2; 4], [1; 3]); ([2], [1; 3; 4]); ([3; 4], [1; 2]); ([3], [1; 2; 4]); ([4], [1; 2; 3]); ([], [1; 2; 3; 4])] # sprinkle [1;3;2];; - : (int list * int list) list = [([1; 3; 2], []); ([1; 3], [2]); ([1; 2], [3]); ([1], [3; 2]); ([3; 2], [1]); ([3], [1; 2]); ([2], [1; 3]); ([], [1; 3; 2])] # sprinkle [’a’;’x’;’g’];; - : (char list * char list) list = [([’a’; ’x’; ’g’], []); ([’a’; ’x’], [’g’]); ([’a’; ’g’], [’x’]); ([’a’], [’x’; ’g’]); ([’x’; ’g’], [’a’]); ([’x’], [’a’; ’g’]); ([’g’], [’a’; ’x’]); ([], [’a’; ’x’; ’g’])]
Consider a tree defined by the following:
type 'a tree = Node of 'a * 'a tree listThis type declaration allows us to represent trees of any arity. Furthermore this definition enforces the requirements that all trees must have at least one Node (i.e. we cannot have "Empty" valued leaves/trees). We will use this definition in the next 3 problems.
Hint: This can be implemented in 3 lines using a higher-order function (since a node's children are stored in a list). How can we aggregate counts in this situation?
This function should have the following type signature:val countNodes : 'a tree -> int = <fun>
val ironOut : int tree -> int list list = <fun>Here are some examples:
#let exampleTree : int tree = Node (1, [Node (2, []); Node (3, [Node (4, []); Node (5, []); Node (6, [Node (7, []); Node (8, []); Node (9, []); Node (10, [])])])]) # ironOut exampleTree;; - : int list list = [[1; 2]; [1; 3; 4]; [1; 3; 5]; [1; 3; 6; 7]; [1; 3; 6; 8]; [1; 3; 6; 9]; [1; 3; 6; 10]]
#let exampleTree2 = Node (1, [ Node (2, []) ; Node (3, []) ; Node (4, [ Node (5, []) ; Node (6, []) ]) ]);; #ironOut exampleTree2;; - : int list list = [[1; 2]; [1; 3]; [1; 4; 5]; [1; 4; 6]]
Fold (also known as reduce) is a popular higher-order functonal method used to aggregate/sumarize information from a bag of elements. This is usually conducted by presenting an aggregation function and state value that are used in conjunction to accumulate information when travering the bag.
We now introduce the concept of unfold, which acts as the reverse (or to be mathematically accurate "the categorical dual") of fold. Here we use an expansion function and state value to generate a bag of elements. For the sake of simplcity, we will only consider the unfold function for lists. We present an implementaton of unfold (in the prelude and below) for lists which takes as input an expansion/generator function, a stop predicate, and a state, and outputs a list generated from the specification of the input. Below is the implementation available in the prelude:
let rec unfold (f: 'seed -> ('a * 'seed)) (stop : 'b -> bool) (b : 'seed) : 'a list = if stop b then [] else begin let x, b' = f b in x :: (unfold f stop b') end ;; val unfold : ('b -> 'a * 'b) -> ('b -> bool) -> 'b -> 'a list = <fun>We see that the generator function takes as input an initial state and generates a new element and a new state. Furthermore, the stop predicate is used to determine when to stop generating elements (since bags are of finite size), conditioned on the state.
We present 2 examples of the use of unfold, available in the prelude, and will use this function to implement the final 2 questions.
# fib 0;; - : int list = [] # fib 1;; - : int list = [1; 1] # fib 2;; - : int list = [1; 1; 2] # fib 3;; - : int list = [1; 1; 2; 3] # fib 20;; - : int list = [1; 1; 2; 3; 5; 8; 13] # fib 21;; - : int list = [1; 1; 2; 3; 5; 8; 13; 21]Hint: Consider an initial state/seed
(fib 0, fib 1) = (1,1)
.
val fib : int -> int list = <fun>
i
the outer most list corresponds to row (i+1)
in pascal's triangle.
# pascal 0;; - : int list list = [] # pascal 1;; - : int list list = [] # pascal 2;; - : int list list = [[1]] # pascal 3;; - : int list list = [[1]; [1; 1]] # pascal 10;; - : int list list = [[1]; [1; 1]; [1; 2; 1]; [1; 3; 3; 1]; [1; 4; 6; 4; 1]; [1; 5; 10; 10; 5; 1]; [1; 6; 15; 20; 15; 6; 1]; [1; 7; 21; 35; 35; 21; 7; 1]; [1; 8; 28; 56; 70; 56; 28; 8; 1]]Hint: Consider the higher order function List.map2.
val pascal : int -> int list list = <fun>


This is tmpl1.html before
This is the value of dot in tmpl1.html - {{ . }}
{{ template "tmpl2.html" . }}
This is tmpl1.html after


CMPUT201W20B2 Week 4
Table of Contents
- 1. Week4
- 1.1. Copyright Statement
- 1.2. Init ORG-MODE
- 1.3. Org Template
- 1.4. Remember how to compile?
- 1.5. Functions
- 1.6. Scope
- 1.7. Global Variables (BAD) / External Variables / File-level variables
- 1.8. Static Function Scope
- 1.9. Pointers!
- 1.9.1. Operators
- 1.9.2. Character Arrays and Pointers
- 1.9.3. Int arrays
- 1.9.4. Arrays as pointers
- 1.9.5. Pointer arthimetic again
- 1.9.6. Hazel's ptrs.c
- 1.9.7. Hazel's ptrconst.c
- 1.9.8. Hazel's Pointer No No's
- 1.9.9. Multidimensional Arrays and Pointers
- 1.9.10. Arrays of Pointers or Pointers of Pointers
- 1.9.11. Confusing Array Pointer interactions and syntax
1 Week4
1.1 Copyright Statement
If you are in CMPUT201 at UAlberta this code is released in the public domain to you.
Otherwise it is (c) 2020 Abram Hindle, Hazel Campbell AGPL3.0+
1.1.1 License
Week 3 notes Copyright (C) 2020 Abram Hindle, Hazel Campbell
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
1.1.2 Hazel Code is licensed under AGPL3.0+
Hazel's code is also found here https://github.com/hazelybell/examples/tree/C-2020-01
Hazel code is licensed: The example code is licensed under the AGPL3+ license, unless otherwise noted.
1.2 Init ORG-MODE
;; I need this for org-mode to work well (require 'ob-sh) ;(require 'ob-shell) (org-babel-do-load-languages 'org-babel-load-languages '((sh . t))) (org-babel-do-load-languages 'org-babel-load-languages '((C . t))) (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) (setq org-src-fontify-natively t)
1.2.1 Org export
(org-html-export-to-html) (org-latex-export-to-pdf) (org-ascii-export-to-ascii)
1.3 Org Template
Copy and paste this to demo C
#include <stdio.h> int main(int argc, char**argv) { return 0; }
1.4 Remember how to compile?
gcc -std=c99 -Wall -pedantic -Werror -o programname programname.c
1.5 Functions
Functions replicate functions in mathematics. They allocate space on the stack and have local variables.
Very similar to python functions
Define a function:
returntype functionName(ArgType1 arg1, ArgType2 arg2, ArgType3 arg3 ) { … }
Call a function:
functionName( arg1, arg2, arg3 );
returntype returnValue = functionName( arg1, arg2, arg3) ;
IN C89 all variable declarations are at the top of the function.
1.5.1 returntypes
- void – nothing
- int
- char
- float
- double
- …
- pointer (array or string)
1.5.2 Example
#include <stdio.h> #include <stdlib.h> void example() { printf("I have been made an example of\n"); // return; // void return } int main() { example(); return 0; }
I have been made an example of
1.5.3 Pass by Value
The value of parameters are COPIED into registers and sometimes the stack. Thus the original variables that the parameters come from are safe.
Except pointers are not safe because given a pointer the called function can manipulate the data the pointer points to, but they cannot modify the original pointer.
#include <stdio.h> #include <stdlib.h> int example(int x) { x++; printf("example x:\t%p\n", (void*)&x); return x; } int main() { int x = 10; printf("main x :\t%p\n", (void*)&x); printf("x: %d\n", x); int rx = example(x); printf("x: %d\n", x); printf("returned x vs x: %d vs %d\n", rx, x); }
main x : 0x7fff242ed010 x: 10 example x: 0x7fff242ecffc x: 10 returned x vs x: 11 vs 10
1.5.4 Arrays again
- void initArray(int cols, int values[cols]) {
- void initArray(int cols, int values[]) {
You can specify array sizes in C99 but the size has to come earlier
- void init2D(int rows, int cols, int values[rows][cols]) {
- void init2D(int rows, int cols, int values[][cols]){
- void init3D(int planes, int rows, int cols, int values[planes][rows][cols]) {
- void init3D(int planes, int rows, int cols, int values[][rows][cols]) {
1.5.5 Don't trust sizeof inside of functions!
sizeof is only trustable if you declared the variable in your scope
#include <stdio.h> #include <stdlib.h> #include <time.h> void init2D(int rows, int cols, int values[][cols]) { int i = 0; printf("init2D: sizeof(values)=%lu\n", sizeof(values)); printf("init2D: sizeof(values[0])=%lu\n", sizeof(values[0])); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { values[row][col] = i++; } } } void example() { unsigned int n = 1 + rand() % 10; unsigned int m = 1 + rand() % 10; printf("%d X %d was chosen!\n", m, n); int values[m][n]; // SO the compiler can't predict this allocation ahead of time printf("sizeof(values) = %ld\n", sizeof(values)); printf("sizeof(&values) = %ld\n", sizeof(&values)); printf("sizeof(values[0]) = %ld\n", sizeof(values[0])); init2D( m, n, values ); } int main() { srand(time(NULL)); //initialze based on the clock example(); example(); example(); }
10 X 4 was chosen! sizeof(values) = 160 sizeof(&values) = 8 sizeof(values[0]) = 16 init2D: sizeof(values)=8 init2D: sizeof(values[0])=16 4 X 3 was chosen! sizeof(values) = 48 sizeof(&values) = 8 sizeof(values[0]) = 12 init2D: sizeof(values)=8 init2D: sizeof(values[0])=12 5 X 5 was chosen! sizeof(values) = 100 sizeof(&values) = 8 sizeof(values[0]) = 20 init2D: sizeof(values)=8 init2D: sizeof(values[0])=20
1.5.6 Returns
Don't return arrays in general.
To return a value and exit the function immediately run:
return expr
#include <stdio.h> #include <stdlib.h> int squareInt(int x) { return x*x; } float squareFloat(float x) { return x*x; } int intDiv(int x, int y) { return x/y; } float floatDiv(float x, float y) { return x/y; } char returnChar( int i ) { return i; } int main() { printf("squareInt\t %d\n", squareInt(25)); printf("squareInt\t %d\n", squareInt(1.47)); printf("squareFloat\t %f\n", squareFloat(1.47)); printf("squareFloat\t %f\n", squareFloat(25)); printf("intDiv\t %d\n", intDiv(64,31)); printf("intDiv\t %d\n", intDiv(64.2,31)); printf("floatDiv\t %f\n", floatDiv(64,31)); printf("floatDiv\t %f\n", floatDiv(64.2,31)); printf("returnChar\t %hhu\n", returnChar( 578 ) ); printf("returnChar\t %hhu\n", returnChar( 'a' ) ); printf("returnChar\t %hhu\n", returnChar( 66.1 ) ); printf("returnChar\t %c\n", returnChar( 578 ) ); printf("returnChar\t %c\n", returnChar( 'a' ) ); printf("returnChar\t %c\n", returnChar( 66.1 ) ); }
squareInt 625 squareInt 1 squareFloat 2.160900 squareFloat 625.000000 intDiv 2 intDiv 2 floatDiv 2.064516 floatDiv 2.070968 returnChar 66 returnChar 97 returnChar 66 returnChar B returnChar a returnChar B
1.5.7 Recursion
- Recursion
- Recursion
- Recursion
#include <stdio.h> #include <stdlib.h> int divisibleBy(int x, int y); int main() { printf("%d\n",divisibleBy(33,32)); } int divisibleBy(int x, int y) { printf("%d %d\n", x,y); if (x == 0) { return 0; } if (y <= 0) { return 0; } if (x % y == 0) { return y; } return divisibleBy(x, y - 1); }
33 32 33 31 33 30 33 29 33 28 33 27 33 26 33 25 33 24 33 23 33 22 33 21 33 20 33 19 33 18 33 17 33 16 33 15 33 14 33 13 33 12 33 11 11
- Recursion
- Recursion
1.5.8 Prototypes
#include <stdio.h> #include <stdlib.h> /* this is a prototype it predeclares that a function with this name will be available. */ // This program will not compile in C99 without this line: // int divisibleBy(int x, int y); int main() { printf("%d\n",divisibleBy(16,15)); } int divisibleBy(int x, int y) { printf("%d %d\n", x,y); if (x == 0) { return 0; } if (y <= 0) { return 0; } if (x % y == 0) { return y; } return divisibleBy(x, y - 1); }
16 15 16 14 16 13 16 12 16 11 16 10 16 9 16 8 8
- Prototypes and corecursive routines
#include <stdio.h> #include <stdlib.h> /* this is a prototype it predeclares that a function with this name will be available. This is useful for co-recursive functions. */ // This program will not compile in C99 without this line: // int aReliesOnB(int x, int y); int bReliesOnA(int x, int y); // int main() { printf("%d\n",aReliesOnB(0,100)); } int aReliesOnB(int x, int y) { printf("> aReliesOnB( %d, %d)\n", x, y); if (x >= y) { return y; } return bReliesOnA(x+x+1, y); } int bReliesOnA(int x, int y) { printf("> bReliesOnA( %d, %d)\n", x, y); if (x >= y) { return y; } return aReliesOnB(x * x + 1, y); }
> aReliesOnB( 0, 100) > bReliesOnA( 1, 100) > aReliesOnB( 2, 100) > bReliesOnA( 5, 100) > aReliesOnB( 26, 100) > bReliesOnA( 53, 100) > aReliesOnB( 2810, 100) 100
1.5.9 Exercise
- - make a recursive countdown function, printing each number until 0 is met.
#include <stdio.h> void countDown(int n) { printf("%d\n",n); if (n > 0) { countDown(n-1); } } int main() { countDown(10); return 0; }
10 9 8 7 6 5 4 3 2 1 0
- - make a recursive fibonacci
fib(0) = 1 fib(1) = 1 fib(n) = fib(n-1) + fib(n-2)
#include <stdio.h> int fibonacci(int n) { if (n == 0 || n == 1) { return 1; } else { return fibonacci(n-1) + fibonacci(n-2); } } int main() { printf("%d\n",fibonacci(45)); return 0; }
1836311903
1.6 Scope
1.6.1 const
Instead of define you can use const for constants.
#include <stdio.h> #include <stdlib.h> const int nine = 9; int catLives(int ncats) { return nine * ncats; } int main() { printf("10 cats %d lives\n", catLives( 10 )); // you can't modify nine // nine++; // *(&nine) = 10; void * totally_not_nine = (void*)&nine; int * not_nine = (int *)totally_not_nine; *not_nine = 10; printf("%d\n",*not_nine); }
1.6.2 Local variables
#include <stdio.h> #include <stdlib.h> // no x here int example(int x) { // < this x is visible -- main's x is NOT visible here x++; // < within return x; // < this scope } // no x here int main() { int x = 10; // < this x is visible within all of main printf("x: %d\n", x); int rx = example(x); printf("x: %d\n", x); printf("returned x vs x: %d vs %d\n", rx, x); }
x: 10 x: 10 returned x vs x: 11 vs 10
1.7 Global Variables (BAD) / External Variables / File-level variables
Too common. Too error prone. You will usually cause lots of bugs by making top-level variables. They will only be available within the file you declare.
Global constants are fine. They are safe.
If you make a global in a file, explicitly limit it to the current file with the static keyword.
If static is not used and the variable is in included files then it will be visible across all files.
#include <stdio.h> #include <stdlib.h> // BAD // int x = 111; // visible in all lines below unless occluded by local definitions // BADISH const int x = 111; // visible in all lines below unless occluded by local definitions // BETTER but still not OK //static int x = 111; // BEST and allowed static const int x = 111; int globalX() { return x; // returns the static global x } int example(int x) { // <x_2 this x, x_2 is visible -- main's x is NOT visible here nor is the global x++; // <x_2 within return x; // <x_2 this scope } int main() { printf("Global x %d\n", globalX()); int x = 10; // < this x, x_3 is visible within all of main const int y = globalX() * globalX(); printf("y: %d\n", y); // x_3 printf("x: %d\n", x); // x_3 int rx = example(x); // x_3 printf("x: %d\n", x); // x_3 printf("returned x vs x: %d vs %d\n", rx, x); // x_3 }
1.8 Static Function Scope
Static function local variables keep their old values. It is similar to defining a global per function
#include <stdio.h> #include <stdlib.h> #include <time.h> unsigned int counter() { static unsigned int counter = 0; // this keeps its value printf("%u\n", counter); return ++counter; } static unsigned int __worseCounter__ = 0; // whoo don't touch this AKA DONT DO IT unsigned int worseCounter() { return ++__worseCounter__; } #define N 10 int main() { srand(time(NULL)); unsigned int count = 0; unsigned int wCount = 0; for (int i = 0 ; i < N; i++) { if (rand() % 3 == 0) { count = counter(); wCount = worseCounter(); } } printf("Counted %u / %u numbers divisible by 3 generated by rand\n", count, N); printf("Worse: Counted %u / %u numbers divisible by 3 generated by rand\n", wCount, N); }
0 1 2 3 4 5 Counted 6 / 10 numbers divisible by 3 generated by rand Worse: Counted 6 / 10 numbers divisible by 3 generated by rand
1.9 Pointers!
- What is a pointer? A number that is a memory address.
- What's at that memory address? the type of the pointer.
- char * str;
- Why?
- you want to know the address so you can manipulate a value or manipulate a shared value.
- you want to return multiple values from a function.
- your computer deals with memory as location and offsets the entire time
- the local variables is the current base pointer + an offset
- What is str? A integer that is a memory address.
- What does str point to? A character, but many an array of characters!
- Can I tell if it is an array of characters? No.
- How can I get the first element of a character array at str?
- str[0]
- *str
- How can I make a pointer to:
- char myChar = 'a';
- char * ptrToMyChar = &myChar;
- Can I manipulate pointers?
- char * ptrToChar = &myChar;
- ptrToChar++; // <— goes to the following character in a character array
- *ptrToChar = 'b'; // Dereference ptrToChar and chance myChar to the value of 'b'
1.9.1 Operators
- & unary operator means "address of"
- * unary operator means "dereference pointer" – that is return the value it points to
- don't confuse declaration of a variable int * x with dereferencing a variable in an expression: *x
#include <stdio.h> #include <stdlib.h> // These are macros they cover up syntax // Return the address of X #define ADDRESSOF(X) (&X) // Dereference X #define DEREF(X) (*X) typedef int * intptr_t; int main() { int i = 99; intptr_t ptrToI1 = ADDRESSOF(i); // these 2 lines int * ptrToI2 = &i; // are the same printf("i: %4d,\naddress of i: %p\n\tptrToI1: %p, *ptrToI1: %d\n\tptrToI2: %p, *ptrToI2: %d\n", i, (void*)&i, (void*)ptrToI1, DEREF(ptrToI1), (void*)ptrToI2, *ptrToI2 ); printf("addressof i: %p,\naddress of ptrToI1: %p\n\tptrToI2: %p\n", (void*)&i, (void*)&ptrToI1, (void*)&ptrToI2 ); return 0; }
i: 99, address of i: 0x7ffc7de54d64 ptrToI1: 0x7ffc7de54d64, *ptrToI1: 99 ptrToI2: 0x7ffc7de54d64, *ptrToI2: 99 addressof i: 0x7ffc7de54d64, address of ptrToI1: 0x7ffc7de54d68 ptrToI2: 0x7ffc7de54d70
1.9.2 Character Arrays and Pointers
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char myChars[] = "Abram believes he is a benevolent professor"; // char * strnstr(const char *big, const char *little, size_t len); from string.h char * professor = strstr(myChars, "professor"); char * believes = strstr(myChars, "believes"); printf("Size of a pointer %lu\n", sizeof(professor)); printf("Location pointed to %p\n", professor); printf("full representation %016lX\n", (long unsigned int)professor); // look how many bits are used printf("myChars: %s\n", myChars); printf("myChars location: %p\n", myChars); printf("professor: %s\n", professor); printf("professor location: %p\n", professor); printf("believes: %s\n", believes); printf("believes location: %p\n", believes); printf("believes - myChars location: %llu\n", (long long unsigned int)believes - (long long unsigned int)myChars); printf("professor - myChars location: %llu\n", (long long unsigned int)professor - (long long unsigned int)myChars); printf("\nBut where are myChars and professor and believes?\n"); printf("myChars location: %p\t ptr address: %p \t*ptr %c\n", (void*)&myChars, myChars, *myChars); printf("professor location: %p\t ptr address: %p \t*ptr %c\n", (void*)&professor, professor, *professor); printf("believes location: %p\t ptr address: %p \t*ptr %c\n", (void*)&believes, believes, *believes); }
Size of a pointer 8 Location pointed to 0x7ffcd335c462 full representation 00007FFCD335C462 myChars: Abram believes he is a benevolent professor myChars location: 0x7ffcd335c440 professor: professor professor location: 0x7ffcd335c462 believes: believes he is a benevolent professor believes location: 0x7ffcd335c446 believes - myChars location: 6 professor - myChars location: 34 But where are myChars and professor and believes? myChars location: 0x7ffcd335c440 ptr address: 0x7ffcd335c440 *ptr A professor location: 0x7ffcd335c430 ptr address: 0x7ffcd335c462 *ptr p believes location: 0x7ffcd335c438 ptr address: 0x7ffcd335c446 *ptr b
1.9.3 Int arrays
Now character arrays are easy because the size is 1 for a character but what about arrays of larger size datatypes?
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000 int main() { int myInts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // char * strnstr(const char *big, const char *little, size_t len); from string.h int * ptrToMyInts = &myInts[0]; int * five = &myInts[5]; int * fiveAgain = myInts + 5; printf("myInts: %p\n", (void*)myInts); printf("ptrToMyInts: %p\n", (void*)ptrToMyInts); printf("five location: %p five value: %d\n", (void*)five, *five); printf("fiveAgain location: %p fiveAgain value: %d\n", (void*)fiveAgain, *fiveAgain); printf("five - myInts location: %llu\n", (long long unsigned int)five - (long long unsigned int)myInts); printf("five - myInts location / sizeof(int): %llu\n", ((long long unsigned int)five - (long long unsigned int)myInts)/(sizeof(int))); printf("\n OK... Where are they?\n"); printf("myInts Location: %p\t ptr address: %p \t*ptr %d\n", (void*)&myInts, (void*)myInts, *myInts); printf("ptrToMyIntsLocation: %p\t ptr address: %p \t*ptr %d\n", (void*)&ptrToMyInts, (void*)ptrToMyInts, *ptrToMyInts); printf("five Location: %p\t ptr address: %p \t*ptr %d\n", (void*)&five, (void*)five, *five); printf("fiveAgain Location: %p\t ptr address: %p \t*ptr %d\n", (void*)&fiveAgain, (void*)fiveAgain, *fiveAgain); printf("\nLet's add 1 to five\n"); int * six = five + 1; printf("five Location: %p\t ptr address: %p \t*ptr %d\n", (void*)&five, (void*)five, *five); printf("six Location: %p\t ptr address: %p \t*ptr %d\n", (void*)&six, (void*)six, *six); }
myInts: 0x7ffcecb13b10 ptrToMyInts: 0x7ffcecb13b10 five location: 0x7ffcecb13b24 five value: 5 fiveAgain location: 0x7ffcecb13b24 fiveAgain value: 5 five - myInts location: 20 five - myInts location / sizeof(int): 5 OK... Where are they? myInts Location: 0x7ffcecb13b10 ptr address: 0x7ffcecb13b10 *ptr 0 ptrToMyIntsLocation: 0x7ffcecb13af0 ptr address: 0x7ffcecb13b10 *ptr 0 five Location: 0x7ffcecb13af8 ptr address: 0x7ffcecb13b24 *ptr 5 fiveAgain Location: 0x7ffcecb13b00 ptr address: 0x7ffcecb13b24 *ptr 5 Let's add 1 to five five Location: 0x7ffcecb13af8 ptr address: 0x7ffcecb13b24 *ptr 5 six Location: 0x7ffcecb13b08 ptr address: 0x7ffcecb13b28 *ptr 6
myInts: 0x7ffd0bdc3f40 ptrToMyInts: 0x7ffd0bdc3f40 five location: 0x7ffd0bdc3f54 five value: 5 fiveAgain location: 0x7ffd0bdc3f54 fiveAgain value: 5 five - myInts location: 20 five - myInts location / sizeof(int): 5
OK… Where are they? myInts Location: 0x7ffd0bdc3f40 ptr address: 0x7ffd0bdc3f40 *ptr 0 ptrToMyIntsLocation: 0x7ffd0bdc3f20 ptr address: 0x7ffd0bdc3f40 *ptr 0 five Location: 0x7ffd0bdc3f28 ptr address: 0x7ffd0bdc3f54 *ptr 5 fiveAgain Location: 0x7ffd0bdc3f30 ptr address: 0x7ffd0bdc3f54 *ptr 5
Let's add 1 to five five Location: 0x7ffd0bdc3f28 ptr address: 0x7ffd0bdc3f54 *ptr 5 six Location: 0x7ffd0bdc3f38 ptr address: 0x7ffd0bdc3f58 *ptr 6
1.9.4 Arrays as pointers
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000 int main() { int myInts[] = { 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int * ptrToMyInts = myInts; int * ptrToMyInts2 = &myInts[0]; printf("myInts:\t%p\n", (void*)myInts); printf("ptrToMyInts:\t%p\n", (void*)ptrToMyInts); printf("ptrToMyInts2:\t%p\n", (void*)ptrToMyInts2); printf("deref myInts:\t%d\n", *myInts); printf("deref ptrToMyInts:\t%d\n", *ptrToMyInts); printf("deref ptrToMyInts2:\t%d\n", *ptrToMyInts2); return 0; }
myInts: 0x7fff16b47c70 ptrToMyInts: 0x7fff16b47c70 ptrToMyInts2: 0x7fff16b47c70 deref myInts: 99 deref ptrToMyInts: 99 deref ptrToMyInts2: 99
1.9.5 Pointer arthimetic again
When you add to pointers you add not just an integer but your n*sizeof(*p) + p where p is a pointer.
*ptr++ is a common idiom, it means give me the current value and transition to the next memory location.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000 int main() { long int myInts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; long int * ptr = &myInts[0]; size_t count = sizeof(myInts) / sizeof(myInts[0]); while(count > 0) { printf("%ld \t %p\n", *ptr, (void*)ptr); ptr++; count--; } ptr = &myInts[10]; count = sizeof(myInts) / sizeof(myInts[0]); while( count-- > 0) { void * oldptr = (void*) ptr; printf("%ld \t %p\t", *ptr--, oldptr); // this *ptr++ is // idiomatic in C and // confusing but you must // learn it printf("ptr - oldptr %ld\n", (unsigned long int)ptr - (unsigned long int)oldptr); } printf("%p %ld\n", (void*)ptr, *ptr); return 0; }
0 0x7ffcdb9b1720 1 0x7ffcdb9b1728 2 0x7ffcdb9b1730 3 0x7ffcdb9b1738 4 0x7ffcdb9b1740 5 0x7ffcdb9b1748 6 0x7ffcdb9b1750 7 0x7ffcdb9b1758 8 0x7ffcdb9b1760 9 0x7ffcdb9b1768 10 0x7ffcdb9b1770 10 0x7ffcdb9b1770 ptr - oldptr -8 9 0x7ffcdb9b1768 ptr - oldptr -8 8 0x7ffcdb9b1760 ptr - oldptr -8 7 0x7ffcdb9b1758 ptr - oldptr -8 6 0x7ffcdb9b1750 ptr - oldptr -8 5 0x7ffcdb9b1748 ptr - oldptr -8 4 0x7ffcdb9b1740 ptr - oldptr -8 3 0x7ffcdb9b1738 ptr - oldptr -8 2 0x7ffcdb9b1730 ptr - oldptr -8 1 0x7ffcdb9b1728 ptr - oldptr -8 0 0x7ffcdb9b1720 ptr - oldptr -8 0x7ffcdb9b1718<PHONE_NUMBER>60448
- Now with Chars
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000 int main() { char str[] = "Polar bears are cool bears"; char * strLiteral = "Polar bears are cool bears"; char * ptr = str; char tmp = 0; while( (tmp = *ptr++) ) { putchar(tmp); } putchar('\n'); ptr = str; tmp = 0; while( (tmp = *ptr++) ) { printf("%c %p %20lu\n", tmp, (void*)ptr, (unsigned long int)ptr); } // now watch the addresses ptr = strLiteral; printf("The start of this function's stack frame is pretty close to %p\n", (void*)&str); while( (tmp = *ptr++) ) { printf("%c %p %20lu\n", tmp, (void*)ptr, (unsigned long int)ptr); } // wow that's super far away in memory printf("str - strLiteral in bytes: %lu\n", (unsigned long int)str - (unsigned long int)strLiteral); printf("&str - &strLiteral in bytes: %lu\n", (unsigned long int)&str - (unsigned long int)&strLiteral); return 0; }
Polar bears are cool bears P 0x7ffdd87de9c1<PHONE_NUMBER>83937 o 0x7ffdd87de9c2<PHONE_NUMBER>83938 l 0x7ffdd87de9c3<PHONE_NUMBER>83939 a 0x7ffdd87de9c4<PHONE_NUMBER>83940 r 0x7ffdd87de9c5<PHONE_NUMBER>83941 0x7ffdd87de9c6<PHONE_NUMBER>83942 b 0x7ffdd87de9c7<PHONE_NUMBER>83943 e 0x7ffdd87de9c8<PHONE_NUMBER>83944 a 0x7ffdd87de9c9<PHONE_NUMBER>83945 r 0x7ffdd87de9ca<PHONE_NUMBER>83946 s 0x7ffdd87de9cb<PHONE_NUMBER>83947 0x7ffdd87de9cc<PHONE_NUMBER>83948 a 0x7ffdd87de9cd<PHONE_NUMBER>83949 r 0x7ffdd87de9ce<PHONE_NUMBER>83950 e 0x7ffdd87de9cf<PHONE_NUMBER>83951 0x7ffdd87de9d0<PHONE_NUMBER>83952 c 0x7ffdd87de9d1<PHONE_NUMBER>83953 o 0x7ffdd87de9d2<PHONE_NUMBER>83954 o 0x7ffdd87de9d3<PHONE_NUMBER>83955 l 0x7ffdd87de9d4<PHONE_NUMBER>83956 0x7ffdd87de9d5<PHONE_NUMBER>83957 b 0x7ffdd87de9d6<PHONE_NUMBER>83958 e 0x7ffdd87de9d7<PHONE_NUMBER>83959 a 0x7ffdd87de9d8<PHONE_NUMBER>83960 r 0x7ffdd87de9d9<PHONE_NUMBER>83961 s 0x7ffdd87de9da<PHONE_NUMBER>83962 The start of this function's stack frame is pretty close to 0x7ffdd87de9c0 P 0x555820b03919<PHONE_NUMBER>2873 o 0x555820b0391a<PHONE_NUMBER>2874 l 0x555820b0391b<PHONE_NUMBER>2875 a 0x555820b0391c<PHONE_NUMBER>2876 r 0x555820b0391d<PHONE_NUMBER>2877 0x555820b0391e<PHONE_NUMBER>2878 b 0x555820b0391f<PHONE_NUMBER>2879 e 0x555820b03920<PHONE_NUMBER>2880 a 0x555820b03921<PHONE_NUMBER>2881 r 0x555820b03922<PHONE_NUMBER>2882 s 0x555820b03923<PHONE_NUMBER>2883 0x555820b03924<PHONE_NUMBER>2884 a 0x555820b03925<PHONE_NUMBER>2885 r 0x555820b03926<PHONE_NUMBER>2886 e 0x555820b03927<PHONE_NUMBER>2887 0x555820b03928<PHONE_NUMBER>2888 c 0x555820b03929<PHONE_NUMBER>2889 o 0x555820b0392a<PHONE_NUMBER>2890 o 0x555820b0392b<PHONE_NUMBER>2891 l 0x555820b0392c<PHONE_NUMBER>2892 0x555820b0392d<PHONE_NUMBER>2893 b 0x555820b0392e<PHONE_NUMBER>2894 e 0x555820b0392f<PHONE_NUMBER>2895 a 0x555820b03930<PHONE_NUMBER>2896 r 0x555820b03931<PHONE_NUMBER>2897 s 0x555820b03932<PHONE_NUMBER>2898 str - strLiteral in bytes:<PHONE_NUMBER>1064 &str - &strLiteral in bytes: 16
1.9.6 Hazel's ptrs.c
The intent here is to demonstrate the use and features of pointers and how to manipulate values via pointers within functions.
#include <stdio.h> int pbv(int passed) { passed++; printf(" passed = %d\n", passed); printf(" &passed = %p\n", (void *) &passed); return passed; } void pbr(int *passed) { printf(" passed = %p\n", (void *) passed); printf(" *passed = %d\n", *passed); printf(" &passed = %p\n", (void *) &passed); (*passed)++; } /* * 4 byte integer (32-bit PC) * Example: our integer uses these 4 bytes * byte<PHONE_NUMBER> (0xff8cad68) * byte<PHONE_NUMBER> (0xff8cad69) * byte<PHONE_NUMBER> (0xff8cad6a) * byte<PHONE_NUMBER> (0xff8cad6b) */ int main() { int thing_1 = 100; int thing_2 = 200; // type: define a_pointer as a pointer to an int int *a_pointer = NULL; // type of a_pointer is "int *" // NULL: the NULL pointer, gives the pointer the value 0 // used to indicate that the pointer doesn't point to anything printf("thing_1 = %d\n", thing_1); printf("thing_2 = %d\n", thing_2); // error: ‘a_pointer’ is used uninitialized in this function [-Werror=uninitialized] //printf("a_pointer = %p\n", (void *) a_pointer); //printf("a_pointer = %zu\n", (size_t) a_pointer); printf("\nsizes:\n"); printf("sizeof(thing_1) = %zu\n", sizeof(thing_1)); printf("sizeof(thing_2) = %zu\n", sizeof(thing_2)); printf("sizeof(a_pointer) = %zu (%zu bits)\n", sizeof(a_pointer), sizeof(a_pointer) * 8); // unary & operator: get address of (reference) a_pointer = &thing_1; printf("\na_pointer = &thing_1;\n"); printf(" &thing_1 = %p\n", (void *) &thing_1); printf(" &thing_2 = %p\n", (void *) &thing_2); printf("a_pointer = %p\n", (void *) a_pointer); printf("a_pointer = %zu\n", (size_t) a_pointer); // unary * operator: get value at (dereference) printf("*a_pointer = %d\n", *a_pointer); a_pointer = &thing_2; printf("\na_pointer = &thing_2;\n"); printf("a_pointer = %p\n", (void *) a_pointer); // unary * operator: get value at (dereference) printf("*a_pointer = %d\n", *a_pointer); // We're going to copy thing_1 and take a look printf("\ncopy value:\n"); printf("\nint value = thing_1;\n"); int value = thing_1; printf("thing_1 = %d\n", thing_1); printf(" value = %d\n", value); printf(" &thing_1 = %p\n", (void *) &thing_1); printf(" &value = %p\n", (void *) &value); printf("\ncopy value using pointer:\n"); printf("\nvalue = *(&thing_2);\n"); value = *(&thing_2); printf("thing_2 = %d\n", thing_2); printf(" value = %d\n", value); printf(" &thing_2 = %p\n", (void *) &thing_2); printf(" &value = %p\n", (void *) &value); printf("\ncopy value using pointer:\n"); a_pointer = &thing_2; printf("\na_pointer = &thing_2;\n"); printf("a_pointer = %p\n", (void *) a_pointer); // unary * operator: get value at (dereference) printf("*a_pointer = %d\n", *a_pointer); printf("value = *a_pointer;\n"); value = *a_pointer; printf("thing_2 = %d\n", thing_2); printf(" value = %d\n", value); printf(" &thing_2 = %p\n", (void *) &thing_2); printf(" &value = %p\n", (void *) &value); printf("\npass-by-value (copy):\n"); printf("\npbv(thing_1);\n"); printf(" thing_1 = %d\n", thing_1); printf(" &thing_1 = %p\n", (void *) &thing_1); pbv(thing_1); printf(" thing_1 = %d\n", thing_1); printf(" &thing_1 = %p\n", (void *) &thing_1); printf("\npass-by-reference (no copy):\n"); printf("\npbr(&thing_1);\n"); printf(" thing_1 = %d\n", thing_1); printf(" &thing_1 = %p\n", (void *) &thing_1); pbr(&thing_1); printf(" thing_1 = %d\n", thing_1); printf(" &thing_1 = %p\n", (void *) &thing_1); return 0; }
thing_1 = 100 thing_2 = 200 sizes: sizeof(thing_1) = 4 sizeof(thing_2) = 4 sizeof(a_pointer) = 8 (64 bits) a_pointer = &thing_1; &thing_1 = 0x7ffdca6654f4 &thing_2 = 0x7ffdca6654f8 a_pointer = 0x7ffdca6654f4 a_pointer =<PHONE_NUMBER>57492 *a_pointer = 100 a_pointer = &thing_2; a_pointer = 0x7ffdca6654f8 *a_pointer = 200 copy value: int value = thing_1; thing_1 = 100 value = 100 &thing_1 = 0x7ffdca6654f4 &value = 0x7ffdca6654fc copy value using pointer: value = *(&thing_2); thing_2 = 200 value = 200 &thing_2 = 0x7ffdca6654f8 &value = 0x7ffdca6654fc copy value using pointer: a_pointer = &thing_2; a_pointer = 0x7ffdca6654f8 *a_pointer = 200 value = *a_pointer; thing_2 = 200 value = 200 &thing_2 = 0x7ffdca6654f8 &value = 0x7ffdca6654fc pass-by-value (copy): pbv(thing_1); thing_1 = 100 &thing_1 = 0x7ffdca6654f4 passed = 101 &passed = 0x7ffdca6654dc thing_1 = 100 &thing_1 = 0x7ffdca6654f4 pass-by-reference (no copy): pbr(&thing_1); thing_1 = 100 &thing_1 = 0x7ffdca6654f4 passed = 0x7ffdca6654f4 *passed = 100 &passed = 0x7ffdca6654d8 thing_1 = 101 &thing_1 = 0x7ffdca6654f4
1.9.7 Hazel's ptrconst.c
The intent here is to show that you shouldn't mess with const vars but you can eventually mutate them with pointers.
#include <stdio.h> int main() { int mut_i = 100; // mutable integer printf("mut_i = %d\n", mut_i); const int const_i = 200; // constant integer printf("const_i = %d\n", const_i); // mutable pointer to mutable integer int * mut_p = &mut_i; printf("mut_p = %p\n", (void *) mut_p); printf("*mut_p = %d\n", *mut_p); // constant pointer to mutable integer int * const const_p = &mut_i; printf("const_p = %p\n", (void *) const_p); printf("*const_p = %d\n", *const_p); // mutable pointer to constant integer const int * p_to_const = &const_i; printf("p_to_const = %p\n", (void *) p_to_const); printf("*p_to_const = %d\n", *p_to_const); // constant pointer to constant integer const int * const const_p_to_const = &const_i; printf("const_p_to_const = %p\n", (void *) const_p_to_const); printf("*const_p_to_const = %d\n", *const_p_to_const); /* // Don't do this! // "warning: assignment discards ‘const’ qualifier from pointer target type" mut_p = &const_i; const char *str_lit = "String literals are const char *"; printf("%s\n", str_lit); // but remember this means we can change str_lit to point to a different string! str_lit = "String literal #2"; printf("%s\n", str_lit); // This protects us from: // str_lit[0] = 'D'; // this is wrong: char *wrong = "We will try to change this string literal"; printf("%s\n", wrong); // Because it doesn't protect us from: // wrong[0] = 'D'; // what happens if you uncomment the above line? // This might be better: const char * const RIGHT = "Don't go changing on me!"; printf("%s\n", RIGHT); // Because it protects us from: // RIGHT[0] = 'L'; // and // RIGHT = wrong; */ }
mut_i = 100 const_i = 200 mut_p = 0x7ffc5e85f080 *mut_p = 100 const_p = 0x7ffc5e85f080 *const_p = 100 p_to_const = 0x7ffc5e85f084 *p_to_const = 200 const_p_to_const = 0x7ffc5e85f084 *const_p_to_const = 200
1.9.8 Hazel's Pointer No No's
Note the lack of flags below.
gcc -std=c99 -Wall -pedantic -o ptr_nonos ptr_nonos.c && \
./ptr_nonos
*pointer = 100 Three fives is 15 *pointer = 22036 Three fives is 15 result = 15 &result = 0x7ffef1c15854 &result_p = 0x7ffef1c15858
#include <stdio.h> #define SIZE 10 // This function tries to print out the int which is at address 0 in memory... // Don't do this! void dereference_null() { printf("\ndereference null\n"); int *a_pointer = NULL; printf(" a_pointer = %p\n", (void *) a_pointer); printf("*a_pointer = %d\n", *a_pointer); } // This function tries to print out the int which is at some address we don't know in memory... // Don't do this! void dereference_uninit() { printf("\ndereference unitialized pointer\n"); int *a_pointer; printf(" a_pointer = %p\n", (void *) a_pointer); printf("*a_pointer = %d\n", *a_pointer); } // This function returns a pointer to an "automatic" local variable... // Don't do this! int *return_pointer_to_local() { int local_int = 100; int *pointer = &local_int; // when we return we give up the memory we allocated for "local_int"! return pointer; } // This function just does some things... int do_things() { int three = 3; int five = 5; int three_fives = three * five; printf(" Three fives is %d\n", three_fives); return three_fives; } int main() { // dereference_null(); int * pointer = return_pointer_to_local(); printf("*pointer = %d\n", *pointer); do_things(); printf("*pointer = %d\n", *pointer); // You can't get a pointer to some things... // This won't compile: // &(do_things()); // We can't do this for the same reason... // &10; // This one is actually exactly the same as the one above... // &SIZE; // You have to make memory to store the value to get a pointer to it! int result = do_things(); printf(" result = %d\n", result); printf(" &result = %p\n", (void *) &result); // This won't compile either. Same reason. // &(&result); // You have to make memory to store the pointer to get a pointer to it! int * result_p = &result; printf("&result_p = %p\n", (void *) &result_p); int **result_pp = &result_p; int ***result_ppp = &result_pp; printf("result_ppp = %p\n", (void *) result_ppp); printf("&result_ppp = %p\n", (void *) &result_ppp); printf("***result_ppp = %d\n", ***result_ppp); return 0; }
*pointer = 100 Three fives is 15 *pointer = 21991 Three fives is 15 result = 15 &result = 0x7ffd6d9af944 &result_p = 0x7ffd6d9af948 result_ppp = 0x7ffd6d9af950 &result_ppp = 0x7ffd6d9af958 ***result_ppp = 15
1.9.9 Multidimensional Arrays and Pointers
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 10 void init2D(int rows, int cols, int values[][cols]) { int i = 0; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { values[row][col] = i++; } } } int main() { int myInts[N][N]; init2D(N, N, myInts); // int * ptrToMyInts = myInts; // THIS WILL NOT WORK int (* ptrToMyInts)[N][N] = &myInts; int (* secondRow)[N] = &myInts[1]; printf("myInts:\t%p\n", (void*)myInts); printf("ptrToMyInts:\t%p\n", (void*)ptrToMyInts); printf("deref myInts:\t%d\n", **myInts); printf("deref myInts + 1:\t%d\n", **(myInts + 1) ); // this hops a row! printf("deref secondRow:\t%d\n", *secondRow[0]); printf("deref *myInts + 1:\t%d\n", *(*myInts + 1) ); // this hops a col! //printf("deref ptrToMyInts:\t%d\n", *ptrToMyInts); return 0; }
myInts: 0x7ffe03eea450 ptrToMyInts: 0x7ffe03eea450 deref myInts: 0 deref myInts + 1: 10 deref secondRow: 10 deref *myInts + 1: 1
1.9.10 Arrays of Pointers or Pointers of Pointers
Be aware that when declaring arrays there are arrays of pointers and pointers to arrays.
They are different.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 4 int main() { char * ptrs[4]; // an array of character poiunters! char stringOnStack[] = "ON STACK"; // these literals will not be on the stack ptrs[0] = "Anaxagoras"; ptrs[1] = "mummifies"; ptrs[2] = "shackles"; ptrs[3] = stringOnStack; printf("sizeof(ptrs)=%lu sizeof(ptrs[0])=%lu\n",sizeof(ptrs), sizeof(ptrs[0])); printf("sizeof(stringOnStack)=%lu sizeof(stringOnStack[0])=%lu\n", sizeof(stringOnStack), sizeof(stringOnStack[0])); printf("sizeof(&stringOnStack)=%lu sizeof(&stringOnStack[0])=%lu\n", sizeof(&stringOnStack), sizeof(&stringOnStack[0])); for (int i = 0; i < N; i++) { printf("S:%s\t", ptrs[i]); printf("P:%p\t", (void*)ptrs[i]); printf("L:%p\n", (void*)&ptrs[i]); } char ** pointsToPointers = ptrs; // it is pointers to pointers (like an array!) printf("sizeof(pointsToPointers)=%lu sizeof(pointsToPointers[0])=%lu\n", sizeof(pointsToPointers), sizeof(pointsToPointers[0])); puts(*(pointsToPointers + 0)); puts(pointsToPointers[0]); putchar('\n'); puts(*(pointsToPointers + 2)); puts(pointsToPointers[2]); putchar('\n'); return 0; }
sizeof(ptrs)=32 sizeof(ptrs[0])=8 sizeof(stringOnStack)=9 sizeof(stringOnStack[0])=1 sizeof(&stringOnStack)=8 sizeof(&stringOnStack[0])=8 S:Anaxagoras P:0x5652a1951978 L:0x7ffd48863760 S:mummifies P:0x5652a1951983 L:0x7ffd48863768 S:shackles P:0x5652a195198d L:0x7ffd48863770 S:ON STACK P:0x7ffd4886378f L:0x7ffd48863778 sizeof(pointsToPointers)=8 sizeof(pointsToPointers[0])=8 Anaxagoras Anaxagoras shackles shackles
1.9.11 Confusing Array Pointer interactions and syntax
- int * myInts != int (* myInts)[]
- Make a pointer to the first element
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5 void init2D(int rows, int cols, int values[][cols]) { int i = 0; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { values[row][col] = i++; } } } int main() { int matrix[N][N]; init2D( N, N, matrix ); int * pointToMatrix = &matrix[0][0]; for (int i = 0; i < N*N; i++) { printf("%c", (i%N==0)?'\n':'\t'); printf("%d", pointToMatrix[i]); } return 0; }
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
- Make a pointer to the first row
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5 #define M 3 void init2D(int rows, int cols, int values[][cols]) { int i = 0; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { values[row][col] = i++; } } } int main() { int matrix[M][N]; init2D( M, N, matrix ); // a pointer to an int array of size [N] int (* pointToRow)[N] = &matrix[0]; printf("sizeof(pointToRow)=%lu\n", sizeof(pointToRow)); printf("sizeof(pointToRow[0])=%lu\n", sizeof(pointToRow[0])); printf("Take a ref to row\n"); for (int i = 0; i < M; i++) { int * row = pointToRow[i]; for (int j = 0 ; j < N; j++) { printf("%d\t", row[j]); } printf("\n"); } printf("Take a ref to row w/ pointer arithmetic\n"); pointToRow = &matrix[0]; for (int i = 0; i < M; i++) { int * row = *pointToRow; //deref that row pointToRow++; // go to next row for (int j = 0 ; j < N; j++) { printf("%d\t", row[j]); } printf("\n"); } printf("Direct index\n"); pointToRow = &matrix[0]; // direct index for (int i = 0; i < M; i++) { for (int j = 0 ; j < N; j++) { printf("%d\t", pointToRow[i][j]); } printf("\n"); } printf("Skip a row\n"); // skip a row pointToRow = &matrix[1]; for (int i = 1; i < M; i++) { // try not to go over our bounds int * row = *pointToRow; //deref that row pointToRow++; // go to next row for (int j = 0 ; j < N; j++) { printf("%d\t", row[j]); } printf("\n"); } return 0; }
sizeof(pointToRow)=8 sizeof(pointToRow[0])=20 Take a ref to row 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Take a ref to row w/ pointer arithmetic 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Direct index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Skip a row 5 6 7 8 9 10 11 12 13 14


The last digest cycle took {{ lastDigestTime | number }} ms and had {{ numWatchers || 0 }} watchers
The last 30 digest cycles averaged {{ last30Digests.time | number }} ms and averaged {{ last30Digests.watchers | number }} watchers.
There were {{ last5Seconds.digests | number }} digests in the last 5 seconds, averaging {{ last5Seconds.digests / 5 | number }} digests/sec
There were {{ last30Seconds.digests | number }} digests in the last 30 seconds, averaging {{ last30Seconds.digests / 30 | number }} digests/sec


Research experience is not required by dental school, but it could reinforce your application if the institutions you are applying to have a research focus,like OSU, UM and UPenn, or if you are particularly interested in conducting research and want to apply to DDS/Ph.D program in some schools.
However, most of the pre-den students who get admitted to good dental school do have some extent of research experience. And publishing a paper is common among pre-dent student. Therefore it is necessary to participate in research during your undergraduate career. While many students think that lab research is most important, experience with social science research is just as fascinating and valuable.
As a famous research institution, OSU encourage undergraduate students to get involved in research and have plenty of research oppotunity. At the same time, most of universities are welcome students from other schools to do research there. You could also land a research job from a company (you could check ASC career service or LinkedIn). Here, we will mainly discuss on-campus research oppotunities. There are three major ways to find an on-campus research position:
If you want to conduct research in specific fields, you could check the corresponding department website. Click on "faculty" or buttons with similar meaning, you could find the department's faculty's information. Most of the faculties list their current/past project and the paper they've published in their biography. They will put a research summary, which including the essense of their research, on the website. Read the summary carefully because you could not read all their projects and papers. You should pick at least 5 faculty members to ask for research oppotunities. Undergraduate Research Office describes every step in finding research oppotunity and applying for that research position. Please check their website for more details.
Undergraduate Research Office (URO) is THE place to help you get involved in the research. You could fina many research oppotunities from their webpage. You can subscribe to the URO email list by sending an email from the email account you want subscribed to<EMAIL_ADDRESS>Then you will receive notification when research oppotunity is available.
If you did well in one of the courses (means you got A or A-) and really like the instructor, you should ask the instructors for research postion in their labs. This is the most easiest way to land a research oppotunity because you both know each other and most professors are willing to let students with excellent performance in their class to join the lab.


This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.
Team Tools
Files 60
Repository activity
Calander
Weekly Tasks
https://github.com/mjherzalla/glue.git
| File | Description | Action |
|---|---|---|
| project | porject file | |
| img | image for banner | |
| design | rough lyout |
Test which is a new approach to have all solutions
11:01 AM | June 9Test which is a new approach to have all solutions
11:01 AM | June 9Test, which is a new approach to have
11:01 AM | YesterdayApollo University, Delhi, India Test
11:01 AM | TodayWe work directly with our designers and suppliers, and sell direct to you, which means quality, exclusive products, at a price anyone can afford.
11:01 AM | Today