Skip to content

Instantly share code, notes, and snippets.

View Atlas7's full-sized avatar

Johnny Chan Atlas7

View GitHub Profile
@Atlas7
Atlas7 / sample_jupyter_notebook_plot.py
Created May 21, 2017 14:16
sample_jupyter_notebook_plot.py
# clean up kernel
%reset -f
# This is a bit of magic to make matplotlib figures appear inline in the notebook
# rather than in a new window.
%matplotlib inline
# Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
@Atlas7
Atlas7 / np_tile.md
Last active May 18, 2017 16:03
NumPy Exercise: Tiling for array creation

Exercise: Tiling for array creation

Skim through the documentation for np.tile, and use this function to construct the array:

[[4, 3, 4, 3, 4, 3],
 [2, 1, 2, 1, 2, 1],
 [4, 3, 4, 3, 4, 3],
 [2, 1, 2, 1, 2, 1]]
@Atlas7
Atlas7 / python_generator_yield.md
Last active October 25, 2019 08:24
Python Generator and Yield - Example

This example illustrate the use of Python generator. (it's like callback function in JavaScript - sort of.)

Example 1

Create a matrix and print result:

M = [[1,2,3],    # this row sum to 6
     [4,5,6],    # this row sum to 15
 [7,8,9]] # this row sum to 24
@Atlas7
Atlas7 / js_vs_py.md
Last active May 15, 2017 19:55
Concatenate elements within an array / list - JavaScript vs Python

Say we want to concatenate elements within a JavaScript array (or Python list). i.e.

  • Input: an array that looks like this ['hello', 'world', '123', '!!!']
  • Process: concatenate the string elements within the array
  • Output: hello world 123 !!!

This post shows the similarity (and difference) of the JavaScript and Python syntax. (in case you start using JavaScript but from a Python background. Or vice versa, start using Python but from a JavaScript background)

JavaScript Solution

@Atlas7
Atlas7 / wordpress-menu
Created May 10, 2017 15:38
wordpress menu php
```.html
<button class="menu-toggle"><?php _e( 'Primary Menu', 'twentyfourteen' ); ?></button>
```
@Atlas7
Atlas7 / fun_js_vs_py.md
Last active September 19, 2019 22:50
Function Programming Example - square elements in an array (JavaScript) or list (Python)

Say we have an array (in JavaScript term) or list (in Python term), this article illustrate a simple functional programming example. i.e.

Input: [1, 2, 3, 4, 5]
Process: square each element
Output: [1, 4, 9, 16, 25]

JavaScript Solution

@Atlas7
Atlas7 / octave_tip.md
Last active April 21, 2017 20:12
Octave - how to scan through words in a long sentence

In Octave, the string manipulation function strtok() can be very handy for scanning through words in a long sentence.

In the following example, we have a sentence:

'hello world how are you'

Assuming all words are separated by a white space, we can repeat this command to extract (1) the word string tok and the remaining sentence s.

@Atlas7
Atlas7 / octave_tip.md
Last active December 23, 2021 17:25
Octave - find the min (or max) value of a Matrix, and the associated row and column

Whilst working through the many (Octave) coding assignment from Andrew Ng's Stanford Machine Learning course, a common problem that I have to solve revolves around this:

Given a Matrix A with m rows, and n columns find the mininum (or maximum) value and the associated row and column number

This article summarises my solution to this problem (which, hopefully this will also come in hadny to you!). Note that Octave index start from 1 (instead of 0).

Sample Matrix

Say we have a Matrix A that look like this:

@Atlas7
Atlas7 / IoTBeekeeper.md
Last active January 4, 2017 22:21
Potential Intel Software Innovator Project - IoT Beekeeper

(Note: this post is in draft mode and is to be updated... JC)

# Intro

Throughout 2017 I will be supporting Clare on becoming a beekeeper. I've never done beekeeping myself before and thought this would be a good opportunity to learn together. Being an Intel Software Innvoator myself I am also keen to potentially build a tech project aligning to beekeeping. No idea as to the problems and solutions just yet. This post serves as a draft scribble notepad for ease of quick references. Will probably put something together to the Intel Developer Mash at some point.

Hybrid Bee-Tech related posts

@Atlas7
Atlas7 / hackathons.md
Created October 19, 2016 11:28
11 Hackathons over 11 Weeks