Skip to content

Instantly share code, notes, and snippets.

View TechMaster's full-sized avatar

Trinh Minh Cuong TechMaster

View GitHub Profile
@TechMaster
TechMaster / functiondemo.js
Last active February 8, 2017 08:26
Demo define and call function
/**
* Created by techmaster on 2/8/17.
*/
/***
* Calculate factorial of n
* @param n {Number} n must be integer and greater than zero
*/
function factorial(n) {
if (isNaN(n)) {
@TechMaster
TechMaster / recursive_block.m
Last active May 1, 2017 12:05
Recursive Block Call
-(void) printString: (NSString*) msg
onComplete: (void (^)(void)) complete{
NSLog(@"%@", msg);
complete();
}
-(void) demoRecursiveBlock
{
__block int index = 0;
NSArray* array = @[@"ABC", @"DEF", @"MNP"];
@TechMaster
TechMaster / swift
Created May 22, 2017 08:44
Animation.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.addBar()
}
func addBar() {
@TechMaster
TechMaster / ShowAlertView.swift
Created June 30, 2017 05:20
ShowAlertView.swift
//
// ViewController.swift
// DisplayAlert
//
// Created by cuong on 6/30/17.
// Copyright © 2017 Techmaster. All rights reserved.
//
import UIKit
@TechMaster
TechMaster / viewcontroller.swift
Created July 3, 2017 08:29
UIViewController life cycle
import UIKit
class ViewController: UIViewController {
override func loadView() {
print("loadView")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@TechMaster
TechMaster / Demo.swift
Created July 11, 2017 08:18
Lỗi ở file demo.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var txtField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@TechMaster
TechMaster / checkString.c
Created September 19, 2017 14:53
Check parentheses matching in String
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int checkHopQuy(char* string);
int main()
{
char string1[] = "a[b]c";
char string2[] = "} abc {";
char string3[] = "<ok string [good]>";
@TechMaster
TechMaster / separateOddEven.cpp
Created October 15, 2017 16:56
Demo Catch.hpp to test the function move all even numbers to left, all odd numbers to right
#include <iostream>
#include <vector>
using namespace std;
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
vector<int> separateOddEven(vector<int> arr) {
auto left = arr.begin();
auto right = arr.end() - 1;
@TechMaster
TechMaster / main.cpp
Created October 15, 2017 17:11
Move all even numbers to left, odd numbers to right
#include <iostream>
#include <vector>
using namespace std;
/*
Chuyển số chẵn về bên trái, số lẻ về bên phải
http://algorithms.tutorialhorizon.com/separate-even-and-odd-integers-in-a-given-array/
int [] arrA = {1,2,3,4,6,8,7,12};
Output: [12, 2, 8, 4, 6, 3, 7, 1]
*/
@TechMaster
TechMaster / printBinary.c
Created October 16, 2017 12:28
Print all binary numbers
#include <iostream>
void printBinary(int n) {
int k;
char *str = (char*) malloc(n * sizeof(char));
memset(str,'0', n); //set str = '00...00'
printf("%s\n", str); //print base string
while (1) {
k = n - 1; //Tinh tu ky tu cuoi
while (k >=0) {
if (str[k] == '0') {