Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
vanessaaleung / main.c
Last active February 23, 2019 07:19
Time Calculation
// Created by Vanessa Leung on 2019/2/22.
#include <stdio.h>
#include <string.h>
//Declare all functions to be used first
//isLeapYear
int leap(int year){
if (((year % 400 == 0) && (year % 3200 != 0)) ||
@vanessaaleung
vanessaaleung / main.c
Created April 17, 2019 06:51
Implement OAuth 2.0 authorization to access Google Drive API in C programming
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
struct MemoryStruct {
char *memory;
size_t size;
};
@vanessaaleung
vanessaaleung / DllImport.cs
Last active May 28, 2019 11:46
DllImport
public class SimpleCloudHandler : MonoBehaviour, ICloudRecoEventHandler
{
[System.Runtime.InteropServices.DllImport("__Internal")]
//Declare the function you want to call in iOS
//e.g. I declare the `unityToIOS` function which I use to pass string to iOS
private static extern void unityToIOS (string str);
}
void OnGUI() {
string name = "Vanessa";
if (GUI.Button (new Rect (10,10,10,10), "More Details")) {
unityToIOS (name);
}
}
void OnGUI() {
string name = "Vanessa";
//if click the button
if (GUI.Button (new Rect (10,10,10,10), "More Details")) {
//execute the iOS func
unityToIOS (name);
}
}
@objc func isDataGet(_ n: NSNotification) {
print(n.userInfo?["data"])
}
@vanessaaleung
vanessaaleung / NotificationCenter_default_addObserver.swift
Last active May 29, 2019 13:16
NotificationCenter.default.addObserver
override func viewDidLoad() {
super.viewDidLoad()
//if receive notification "NotificationName", execute func `isDataGet`
NotificationCenter.default.addObserver(self, selector: #selector(isDataGet(_:)),
name: NSNotification.Name("NotificationName") , object: nil)
}
@vanessaaleung
vanessaaleung / unityToIOS.mm
Last active May 28, 2019 11:52
unityToIOS
extern "C" void unityToIOS(char *str) {
//add things you want to pass to iOS here
//e.g. I want to pass a string, I save the string in NSDictionary and assign it to userInfo
NSString* objcstring = @(str);
NSDictionary* dict = @{ @"data": objcstring};
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName"
object:nil userInfo:dict];
}
@vanessaaleung
vanessaaleung / WriteMemoryCallback.c
Last active May 29, 2019 05:58
WriteMemoryCallback
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
//struct in C is similar to class
struct MemoryStruct {
char *memory;
size_t size; //size_t is an unsigned integer type of at least 16 bit
@vanessaaleung
vanessaaleung / main.c
Created May 29, 2019 05:49
Main function
int main(void)
{
CURL *curl_handle, curl_handle2;
CURLcode res;
struct MemoryStruct chunk;
//malloc(size of memory blocks in bytes): allocates requested memory and returns pointer to it
chunk.memory = malloc(1); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */