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 / main.c
Created January 9, 2020 03:37
C Callback function
/* main.c */
#include <stdio.h>
#include "para_callback.h"
void say_hello(void *str)
{
printf("Hello %s\n", (const char *)str);
}
void count_numbers(void *num)
@frankie-yanfeng
frankie-yanfeng / main.c
Last active January 8, 2020 08:05
Two Layer Pointers
/* main.c */
#include <stdio.h>
#include "redirect_ptr.h"
int main(void)
{
const char *firstday = NULL;
const char *secondday = NULL;
get_a_day(&firstday);
get_a_day(&secondday);
@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")
}
@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 / 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 / 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 / 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 / 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 / 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 / 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;
}