Skip to content

Instantly share code, notes, and snippets.

View Atlas7's full-sized avatar

Johnny Chan Atlas7

View GitHub Profile
@Atlas7
Atlas7 / Intel_Groove_LightSensorTriggerLEDs.md
Last active October 17, 2015 15:16
Hardware Project: Mouse Detector (with Light Sensor and LEDs)

How to find out when the mouse been eating my KitKat? A Mouse Detector built with Light Sensor and LEDs - just another fun project using Intel Edison Board, Arduino, Groove Light Sensor, Groove LEDs. See link below for NodeJS Script (to be run via Intel XDK IoT IDE).

I essentially started from the Groove LED script template and Groove Light Sensor script template, and combined the two ideas together. And we have a Light-sensor triggering LEDs mechanism! :)

See this YouTube demo.

/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// Leave the above lines for propper jshinting
@Atlas7
Atlas7 / js_func_test.md
Created October 26, 2015 10:47
JavaScript - Parsing function as an argument

Quick JavaScript demo:

  • parsing function as an argument
  • assigning a function as a variable (essentially making a copy of the function under a different name)
function sumIt (a, b) {
	console.log("sumIt...")
	return a + b;
};
@Atlas7
Atlas7 / javascript_function_syntax.md
Created October 30, 2015 13:49
JavaScript - Function Syntax

Learnt a new type of syntax around function today, so thought I would make a quick note here!

The following two examples are equivalent:

Example 1

var i = 1;
console.log( function (j) {return j+100} (i) ) ;
// return 101
@Atlas7
Atlas7 / mac_shortcuts.md
Created January 12, 2016 10:13
Some very handy Mac shortcuts

Dan Rodney has some great Mac shortcuts at his blog here. Below are some of my favorites.

shortcut description
cmd + tab switch apps
cmd + alt + left/right arrow switch tab within an app
cmd + ` (backtick) switch windows within the same app
@Atlas7
Atlas7 / blogpost.md
Created January 12, 2016 15:27
Udacity - Web Development - API - Parse XML with Python minidom library

Some sample scripts to demo parsing XML with Python minidom library. Taken from the Udacity Web Development Course - this lesson.

Unknown:apps johnny$ ipython
Python 2.7.10 |Anaconda 2.4.0 (x86_64)| (default, Oct 19 2015, 18:31:17) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
@Atlas7
Atlas7 / blogpost.md
Last active January 12, 2016 15:47
Udacity - Web Development - Python urllib2

Some simple iPython scripts to illustrate the use of Python urllib2 library. e.g. to interact with the web.

Unknown:apps johnny$ ipython
Python 2.7.10 |Anaconda 2.4.0 (x86_64)| (default, Oct 19 2015, 18:31:17) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
@Atlas7
Atlas7 / blogpost.md
Last active January 12, 2016 17:29
Udacity - Web Development - Escaping JSON in Python

Some examples of JSON escaping in Python (use double back slashes within a string, or single slash within a raw string):

In [1]: import json

In [9]: json.loads('{"story":"oh \\"my\\" word!"}')
Out[9]: {u'story': u'oh "my" word!'}

In [10]: json.loads(r'{"story":"oh \"my\" word!"}')
Out[10]: {u'story': u'oh "my" word!'}
@Atlas7
Atlas7 / blogpost.md
Last active January 12, 2016 17:39
Udacity - Web Development - Two ways to load JSON in Python

Two ways to load JSON in Python - taken from this video Udacity - Web Development video:

In [14]: json.loads(r'{"story":"once upon a time"}')
Out[14]: {u'story': u'once upon a time'}

In [12]: json.dumps({"story":"once upon a time"})
Out[12]: '{"story": "once upon a time"}'
@Atlas7
Atlas7 / blogpost.md
Last active January 17, 2016 17:04
Udacity - Web Development - Simple Cached Computation - Python Code

Here is a nice and simple Python code illustrating a simple implementation of caching - taken from Udacity - Web Development - Caching. i.e. given the same inputs, the computation is only performed once. Some benefits of this approach: (1) reduce load on server, (2) reduce number of read/write against database, (3) faster queries.

# Code

import time

# complex_computation() simulates a slow function. time.sleep(n) causes the
# program to pause for n seconds. In real life, this might be a call to a
# database, or a request to another web service.