Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View frankie-yanfeng's full-sized avatar
🎬
"What I cannot create, I do not understand" - Richard Feynman

Yan Feng frankie-yanfeng

🎬
"What I cannot create, I do not understand" - Richard Feynman
View GitHub Profile
@frankie-yanfeng
frankie-yanfeng / comma_sep.cpp
Created March 3, 2019 06:11
how to parser comma separated string in c++
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <sstream>
using namespace std;
int main() {
char Name[30];
@frankie-yanfeng
frankie-yanfeng / privateConstructor.cpp
Created March 3, 2019 06:12
C++ Private Constructor
class WonderfulClass
{
public:
static WonderfulClass* makeAnObject()
{
// 创建一个WonderfulClass对象并返回其指针
return (new WonderfulClass);
}
private:
WonderfulClass() { }
@frankie-yanfeng
frankie-yanfeng / constructorArray.cpp
Created March 3, 2019 06:15
C++ constructor array
#include <iostream>
using namespace std;
class CSample {
int x;
public:
CSample() {
cout << "Constructor 1 Called" << endl;
}
@frankie-yanfeng
frankie-yanfeng / typeChangeConstructor.cpp
Created March 3, 2019 07:25
C++ type change constructor
#include <iostream>
using namespace std;
class Complex {
public:
double real, imag;
Complex( int i ) { //类型转换构造函数
cout << "IntConstructor called" << endl;
real = i; imag = 0;
@frankie-yanfeng
frankie-yanfeng / enclosing.cpp
Last active March 3, 2019 08:02
C++ enclosing
class CTyre { //轮胎类
private:
int radius; //半径
int width; //宽度
public:
CTyre(int r, int w):radius(r), width(w) { }
};
class CEngine { //引擎类
};
@frankie-yanfeng
frankie-yanfeng / operatorOverriding.cpp
Created March 3, 2019 09:19
C++ operator Overriding (operator function)
#include <iostream>
using namespace std;
class Complex {
public:
Complex( double r = 0.0, double i= 0.0 ){
real = r;
imaginary = i;
}
@frankie-yanfeng
frankie-yanfeng / operatorOverridingMemberFunction.cpp
Created March 3, 2019 09:27
C++ operator overriding member function
#include <iostream>
using namespace std;
class Complex {
public:
Complex( double r= 0.0, double m = 0.0 ):real(r), imaginary(m) { } // constructor
Complex operator+ ( const Complex & ); // addition
Complex operator- ( const Complex & ); // subtraction
void getValue(){ cout << "real:" << this->real << " imaginary:" << this->imaginary << endl;}
@frankie-yanfeng
frankie-yanfeng / sql_query.py
Created April 17, 2019 10:03
SQL python function
# Create function that finds the number of records and the average weight for each value of the chosen column
def get_distinct_values(column_name):
sql = """
SELECT
{0},
COUNT(1) AS num_babies,
AVG(weight_pounds) AS avg_wt
FROM
publicdata.samples.natality
WHERE
@frankie-yanfeng
frankie-yanfeng / gcp_bucket_creation.py
Created April 17, 2019 10:08
create the env variables to call gsutil command
# change these to try this notebook out
BUCKET = 'cloud-training-demos-ml'
PROJECT = 'cloud-training-demos'
REGION = 'us-central1'
import os
os.environ['BUCKET'] = BUCKET
os.environ['PROJECT'] = PROJECT
os.environ['REGION'] = REGION
@frankie-yanfeng
frankie-yanfeng / forRangeNoMemoryCost.go
Last active October 25, 2019 02:52
for range without memory cost
package main
import "fmt"
func main() {
var times [5][0]int
for range times {
fmt.Println("hello")
}