Skip to content

Instantly share code, notes, and snippets.

View martin-mok's full-sized avatar
🏠
Working from home

Martin martin-mok

🏠
Working from home
  • Hong Kong
View GitHub Profile
def isSubset(A,B):
"""
takes two arrays as input, each array contains a list of A-Z;
return True if all the elements in 2nd array is also in 1st array, or False if not.
"""
for i in range(len(B)):
found=False
for j in range(len(A)): #check if each character of B is found in A
if B[i] == A[j]:
found=True

the nextFibonacci(fList) takes an array of fibonacci numbers, and tell you all the next fibonacci numbers
Insde it, we use a helper function nextF(f) that find the next fibonacci number of a fibonacci number f

Implementations are written in Python

Code1:Implementation of nextFibonacci(fList)

def nextFibonacci(fList):
"""
a function that takes an array of integers as input. For each integer, output the next fibonacci number.
"""
 try:
/*
It's a scoping bug, it can be corrected by using let
*/
function createArrayOfFunctions(y) {
/*
A function that create an array of function, each have one input, and return the input value by adding the index
*/
let arr = [];
for (let i = 0; i < y; i++) {
arr[i] = function(x) {
@martin-mok
martin-mok / PY0101EN-1-1-Types.ipynb
Created June 4, 2019 14:09 — forked from netappzone/PY0101EN-1-1-Types.ipynb
Created on Cognitive Class Labs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@martin-mok
martin-mok / readme.md
Created June 4, 2019 14:31 — forked from benstr/readme.md
Gist Markdown Cheatsheet

#Heading 1 ##Heading 2 ###Heading 3 ####Heading 4 #####Heading 5 ######Heading 6


Paragraph

<?php
/*
The problem is here:
https://www.hackerrank.com/challenges/compare-the-triplets/problem
Reference: Code for creating a simple php calculator for debugging
https://stackoverflow.com/questions/21445245/simple-php-calculator
*/
$result = "";
function compareTriplets($a, $b) {
@martin-mok
martin-mok / codereview.md
Created June 16, 2019 12:42 — forked from addyosmani/codereview.md
Lessons from a JavaScript code review

#Lessons From A JavaScript Code Review

I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.

##Challenges & Solutions

Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.

Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete

@martin-mok
martin-mok / num_guess.ipynb
Last active July 7, 2019 09:00
The very basic of guessing a random number
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@martin-mok
martin-mok / Form_post_testing.php
Created August 14, 2019 01:24
Form_post_testing
<?php
echo nl2br(__LINE__ . "\n" . __FILE__ . " " . __DIR__ . "\n" . __NAMESPACE__ . strval(1+2) . "\n" . "abc\n");
?>
<script>
function submit_action(action, edit_id){
document.getElementById('action').value=action;
document.getElementById('edit_id').value=edit_id;
if(action=="bad_weather"){
/*
@martin-mok
martin-mok / connect_DB_with_port.php
Created August 14, 2019 01:35
php code to connect mysql wtih different port
<?php
//for default MySQL port 3306
//$servername = "127.0.0.1";
//for MySQL deployed on port 3308
$servername = "127.0.0.1:3308";
$username = "root";
$password = "";
try {
$pdo = new PDO("mysql:host=$servername;", $username, $password);
// set the PDO error mode to exception