Imported all the notebooks
[tm351-notebooks.git] / notebooks / .ipynb_checkpoints / styled_demo-checkpoint.ipynb
1 {
2 "metadata": {
3 "name": "",
4 "signature": "sha256:50341e352da58ade3ede73c64ef09e12929bbc2a0bc5d83e94306c8a67462321"
5 },
6 "nbformat": 3,
7 "nbformat_minor": 0,
8 "worksheets": [
9 {
10 "cells": [
11 {
12 "cell_type": "code",
13 "collapsed": false,
14 "input": [
15 "!curl -L https://gist.githubusercontent.com/psychemedia/b0c218135d2698648cbe/raw/activityCodeCell.js > $(ipython locate profile)/static/custom/activityCodeCell.js \n",
16 "#In $(ipython locate profile)/static/custom/custom.js\n",
17 "## $([IPython.events]).on('app_initialized.NotebookApp', function(){ require(['custom/answer_buttons'])});\n",
18 "!sed -i '$a $([IPython.events]).on(\"app_initialized.NotebookApp\", function(){ require([\"custom/activityCodeCell\"])});' $(ipython locate profile)/static/custom/custom.js"
19 ],
20 "language": "python",
21 "metadata": {
22 "activity": false
23 },
24 "outputs": [
25 {
26 "output_type": "stream",
27 "stream": "stdout",
28 "text": [
29 " % Total % Received % Xferd Average Speed Time Time Time Current\r\n",
30 " Dload Upload Total Spent Left Speed\r\n",
31 "\r",
32 " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0"
33 ]
34 },
35 {
36 "output_type": "stream",
37 "stream": "stdout",
38 "text": [
39 "\r",
40 " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0"
41 ]
42 },
43 {
44 "output_type": "stream",
45 "stream": "stdout",
46 "text": [
47 "\r",
48 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0\r",
49 "100 2151 0 2151 0 0 1120 0 --:--:-- 0:00:01 --:--:-- 1120\r\n"
50 ]
51 },
52 {
53 "output_type": "stream",
54 "stream": "stdout",
55 "text": [
56 "sed: 1: \"/Users/ajh59/.ipython/p ...\": command a expects \\ followed by text\r\n"
57 ]
58 }
59 ],
60 "prompt_number": 3
61 },
62 {
63 "cell_type": "code",
64 "collapsed": false,
65 "input": [
66 "!curl -L https://gist.githubusercontent.com/psychemedia/273b72fd2256c4efdd85/raw/answer_button.js > $(ipython locate profile)/static/custom/answer_buttons.js "
67 ],
68 "language": "python",
69 "metadata": {
70 "activity": false
71 },
72 "outputs": [
73 {
74 "output_type": "stream",
75 "stream": "stdout",
76 "text": [
77 " % Total % Received % Xferd Average Speed Time Time Time Current\r\n",
78 " Dload Upload Total Spent Left Speed\r\n",
79 "\r",
80 " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0"
81 ]
82 },
83 {
84 "output_type": "stream",
85 "stream": "stdout",
86 "text": [
87 "\r",
88 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0"
89 ]
90 },
91 {
92 "output_type": "stream",
93 "stream": "stdout",
94 "text": [
95 "\r",
96 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0"
97 ]
98 },
99 {
100 "output_type": "stream",
101 "stream": "stdout",
102 "text": [
103 "\r",
104 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0"
105 ]
106 },
107 {
108 "output_type": "stream",
109 "stream": "stdout",
110 "text": [
111 "\r",
112 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0"
113 ]
114 },
115 {
116 "output_type": "stream",
117 "stream": "stdout",
118 "text": [
119 "\r",
120 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0"
121 ]
122 },
123 {
124 "output_type": "stream",
125 "stream": "stdout",
126 "text": [
127 "\r",
128 " 0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0"
129 ]
130 },
131 {
132 "output_type": "stream",
133 "stream": "stdout",
134 "text": [
135 "\r",
136 "100 1302 0 1302 0 0 217 0 --:--:-- 0:00:05 --:--:-- 375\r\n"
137 ]
138 }
139 ],
140 "prompt_number": 2
141 },
142 {
143 "cell_type": "markdown",
144 "metadata": {},
145 "source": [
146 "Now try answering a few more questions by making your own queries on to the database:"
147 ]
148 },
149 {
150 "cell_type": "code",
151 "collapsed": false,
152 "input": [
153 "##What is the capital of Chad?\n"
154 ],
155 "language": "python",
156 "metadata": {
157 "activity": true
158 },
159 "outputs": []
160 },
161 {
162 "cell_type": "code",
163 "collapsed": false,
164 "input": [
165 "#Not example text"
166 ],
167 "language": "python",
168 "metadata": {
169 "activity": false
170 },
171 "outputs": []
172 },
173 {
174 "cell_type": "code",
175 "collapsed": false,
176 "input": [
177 "#Your text here\n",
178 "print(\"sdsds\")"
179 ],
180 "language": "python",
181 "metadata": {
182 "activity": true
183 },
184 "outputs": [
185 {
186 "output_type": "stream",
187 "stream": "stdout",
188 "text": [
189 "sdsds\n"
190 ]
191 }
192 ],
193 "prompt_number": 1
194 },
195 {
196 "cell_type": "markdown",
197 "metadata": {},
198 "source": [
199 "I'm not sure how to propagate a lighter blue colour via CSS up the DOM?"
200 ]
201 },
202 {
203 "cell_type": "markdown",
204 "metadata": {},
205 "source": [
206 "THis is an activity block\n",
207 "\n",
208 "Do a thing \n",
209 "\n",
210 "<div class=\"answer\" id=\"ans1\" style=\"display: none\">\n",
211 "Some possible ways of expressing the queries as English questions are:\n",
212 "a.List all the information about the countries whose capital is Helsinki.\n",
213 "b.List the ISO codes of every country which has Portuguese as an official language.\n",
214 "c.List the name of every country in Asia which does not have a capital city.</div>"
215 ]
216 },
217 {
218 "cell_type": "markdown",
219 "metadata": {},
220 "source": [
221 "blah"
222 ]
223 },
224 {
225 "cell_type": "markdown",
226 "metadata": {},
227 "source": [
228 "<div class=\"activity\">Activity</div>\n",
229 "\n",
230 "Try and do a thing in the code cell below - if you need a hint, try the answe\n",
231 "\n"
232 ]
233 },
234 {
235 "cell_type": "code",
236 "collapsed": false,
237 "input": [
238 "#You do a thing...\n",
239 "print('asdsd')\n",
240 "a=\"1\\nwew\"\n",
241 "df[:3]"
242 ],
243 "language": "python",
244 "metadata": {
245 "activity": true
246 },
247 "outputs": [
248 {
249 "output_type": "stream",
250 "stream": "stdout",
251 "text": [
252 "asdsd\n"
253 ]
254 },
255 {
256 "ename": "NameError",
257 "evalue": "name 'df' is not defined",
258 "output_type": "pyerr",
259 "traceback": [
260 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
261 "\u001b[0;32m<ipython-input-3-1a26c54b6484>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'asdsd'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"1\\nwew\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
262 "\u001b[0;31mNameError\u001b[0m: name 'df' is not defined"
263 ]
264 }
265 ],
266 "prompt_number": 3
267 },
268 {
269 "cell_type": "markdown",
270 "metadata": {},
271 "source": [
272 "more teaching text\n",
273 "<div class=\"answer\" id=\"ans2\" style=\"display: none\">\n",
274 "Some possible ways of expressing the queries as English questions are:\n",
275 "a.List all the information about the countries whose capital is Helsinki.\n",
276 "b.List the ISO codes of every country which has Portuguese as an official language.\n",
277 "c.List the name of every country in Asia which does not have a capital city.</div>"
278 ]
279 },
280 {
281 "cell_type": "code",
282 "collapsed": false,
283 "input": [
284 "!sed -i '$a $([IPython.events]).on(\"app_initialized.NotebookApp\", function(){ require([\"custom/activityCodeCell\"])});' $(ipython locate profile)/static/custom/custom.js"
285 ],
286 "language": "python",
287 "metadata": {
288 "activity": false
289 },
290 "outputs": [
291 {
292 "output_type": "stream",
293 "stream": "stdout",
294 "text": [
295 "sed: 1: \"/Users/ajh59/.ipython/p ...\": command a expects \\ followed by text\r\n"
296 ]
297 }
298 ],
299 "prompt_number": 5
300 },
301 {
302 "cell_type": "code",
303 "collapsed": false,
304 "input": [
305 "!head -n 500 /Users/ajh59/.ipython/profile_default/static/custom/custom.js"
306 ],
307 "language": "python",
308 "metadata": {
309 "activity": false
310 },
311 "outputs": [
312 {
313 "output_type": "stream",
314 "stream": "stdout",
315 "text": [
316 "// leave at least 2 line with only a star on it below, or doc generation fails\r\n",
317 "/**\r\n",
318 " *\r\n",
319 " *\r\n",
320 " * Placeholder for custom user javascript\r\n",
321 " * mainly to be overridden in profile/static/custom/custom.js\r\n",
322 " * This will always be an empty file in IPython\r\n",
323 " *\r\n",
324 " * User could add any javascript in the `profile/static/custom/custom.js` file\r\n",
325 " * (and should create it if it does not exist).\r\n",
326 " * It will be executed by the ipython notebook at load time.\r\n",
327 " *\r\n",
328 " * Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook.\r\n",
329 " *\r\n",
330 " * Example :\r\n",
331 " *\r\n",
332 " * Create a custom button in toolbar that execute `%qtconsole` in kernel\r\n",
333 " * and hence open a qtconsole attached to the same kernel as the current notebook\r\n",
334 " *\r\n",
335 " * $([IPython.events]).on('app_initialized.NotebookApp', function(){\r\n",
336 " * IPython.toolbar.add_buttons_group([\r\n",
337 " * {\r\n",
338 " * 'label' : 'run qtconsole',\r\n",
339 " * 'icon' : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons\r\n",
340 " * 'callback': function () {\r\n",
341 " * IPython.notebook.kernel.execute('%qtconsole')\r\n",
342 " * }\r\n",
343 " * }\r\n",
344 " * // add more button here if needed.\r\n",
345 " * ]);\r\n",
346 " * });\r\n",
347 " *\r\n",
348 " * Example :\r\n",
349 " *\r\n",
350 " * Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );`\r\n",
351 " * to load custom script into the notebook.\r\n",
352 " *\r\n",
353 " * // to load the metadata ui extension example.\r\n",
354 " * $.getScript('/static/notebook/js/celltoolbarpresets/example.js');\r\n",
355 " * // or\r\n",
356 " * // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert\r\n",
357 " * $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js');\r\n",
358 " *\r\n",
359 " *\r\n",
360 " * @module IPython\r\n",
361 " * @namespace IPython\r\n",
362 " * @class customjs\r\n",
363 " * @static\r\n",
364 " */\r\n"
365 ]
366 }
367 ],
368 "prompt_number": 4
369 },
370 {
371 "cell_type": "code",
372 "collapsed": false,
373 "input": [
374 "! ls $(ipython locate profile)/static/custom"
375 ],
376 "language": "python",
377 "metadata": {
378 "activity": false
379 },
380 "outputs": [
381 {
382 "output_type": "stream",
383 "stream": "stdout",
384 "text": [
385 "activityCodeCell.js answer_buttons.js custom.css custom.js\r\n"
386 ]
387 }
388 ],
389 "prompt_number": 4
390 },
391 {
392 "cell_type": "code",
393 "collapsed": false,
394 "input": [
395 "!head -n 500 $(ipython locate profile)/static/custom/answer_buttons.js"
396 ],
397 "language": "python",
398 "metadata": {
399 "activity": false
400 },
401 "outputs": [
402 {
403 "output_type": "stream",
404 "stream": "stdout",
405 "text": [
406 "\"using strict\";\r\n",
407 "var answer_buttons = (function() {\r\n",
408 "\r\n",
409 " function add_buttons(){\r\n",
410 " console.log(\"runit\");\r\n",
411 " $(\"div\").each( function(){\r\n",
412 " if (this.className === 'answer') {\r\n",
413 " var button= '<input type=\"button\" value=\"Answer\" onclick=\"showHide(' + this.id + ')\">';\r\n",
414 " this.insertAdjacentHTML(\"beforeBegin\",button);\r\n",
415 " }\r\n",
416 " });\r\n",
417 " };\r\n",
418 "\r\n",
419 "$([IPython.events]).on('notebook_loaded.Notebook',add_buttons());\r\n",
420 "\r\n",
421 " IPython.toolbar.add_buttons_group([\r\n",
422 " {\r\n",
423 " id : 'add_buttons',\r\n",
424 " label : 'Add answer buttons',\r\n",
425 " icon : 'icon-list-alt',\r\n",
426 " callback : add_buttons\r\n",
427 " }\r\n",
428 " ]);\r\n",
429 " \r\n",
430 "})();\r\n",
431 "\r\n",
432 "function showHide(e) {\r\n",
433 " if(e.style.display == 'block')\r\n",
434 " e.style.display = 'none';\r\n",
435 " else\r\n",
436 " e.style.display = 'block';\r\n",
437 "}\r\n"
438 ]
439 }
440 ],
441 "prompt_number": 1
442 },
443 {
444 "cell_type": "code",
445 "collapsed": false,
446 "input": [],
447 "language": "python",
448 "metadata": {
449 "activity": false
450 },
451 "outputs": []
452 }
453 ],
454 "metadata": {}
455 }
456 ]
457 }