Skip to content

Instantly share code, notes, and snippets.

@ashraf267
ashraf267 / no_loop.dart
Created August 3, 2023 23:30
I solved a simple: print 1 - 100 without using a loop. I simply used recursion!
void main() {
// instantiation
final noLoop = NoLoop(max: 100);
// method call:- prints 1 - 100
noLoop.withoutLoop();
}
class NoLoop {
static int i = 0;
@ashraf267
ashraf267 / rock_paper_scissors.dart
Created August 3, 2023 23:32
Although needs minor tweak, I managed to write a command-line Rock, Paper & Scissors dart game.
import 'dart:io';
import 'dart:math';
enum Options { r, p, s }
void main() {
// call func
rockPaperScissors();
}
@ashraf267
ashraf267 / ucard.c
Created August 16, 2023 05:29
This works enough for the proof of concept. created at 6:29am on Wednesday, 16th of AUG, 2023
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "net_if.h"
#include "jsmn.h"
// string replace function
char *replace(
char const *const original,
char const *const pattern,
@ashraf267
ashraf267 / ucard.c
Created August 16, 2023 10:10
This looks like it works, but needs some tweaks. At 11:10am 16/08/23
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "net_if.h"
#include "jsmn.h"
// string replace function
char *replace(
char const *const original,
char const *const pattern,
@ashraf267
ashraf267 / Demo.c
Created August 28, 2023 07:53
This code appears to be working with API. I want to tweak it and get back to it later.
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "jsmn.h"
// cust replace func
// char *replace(char const *const original, char const *const pattern, char const *const replacement)
// {
// size_t const replen = strlen(replacement);
// size_t const patlen = strlen(pattern);
@ashraf267
ashraf267 / Demo.c
Created August 28, 2023 12:16
v2 of Demo.c - it crashes
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "jsmn.h"
const char* GetWallet(unsigned char *pcOut)
{
short sRC;
char url[] = "https://devapi.ucard.store/identity/Agent/login/wallet/initate";
@ashraf267
ashraf267 / Demo.c
Created August 28, 2023 23:01
This really looks promising
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "jsmn.h"
short makeApiCall(char *url, unsigned char *requestData, unsigned short requestDataLength)
{
short sRC;
// sRC = UIWireHttpSend(url, requestData, requestDataLength, NULL);
sRC = UIWireHttpSend(url, requestData, requestDataLength, "Content-Type: application/json\r\n");
@ashraf267
ashraf267 / Demo.c
Created August 30, 2023 09:00
Shows "Api call failed" to the screen
short makeApiCall(char *url, unsigned char *requestData, unsigned short requestDataLength)
{
short sRC;
sRC = UIWireHttpSend(url, requestData, requestDataLength, NULL);
// sRC = UIWireHttpSend(url, requestData, requestDataLength, "Content-type: application/json; charset=UTF-8");
return sRC;
// if (sRC != TY_OK)
// {
// return sRC; // failed, I think
// }
@ashraf267
ashraf267 / Demo.c
Created September 6, 2023 10:17
This kind of works for calling api. not fully tested.
#include "Ui.h"
#include "Common.h"
#include "Communication.h"
#include "jsmn.h"
#include "LibApi.h"
#include "Print.h"
#include "MessageBox.h"
#include "net_if.h"
// for print
@ashraf267
ashraf267 / Demo.c
Created September 11, 2023 13:49
Sample code to be shared with Faruk
short TestGet(int iTimeout)
{
int sRC = -1;
unsigned char ucRecvBuff[3500] = {0};
unsigned short usRecvBUffLen = sizeof(ucRecvBuff);
// char *myHeader = "{\"Host\": \"dev.ucard.store\r\n\", \"Authorization\": \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9lbWFpbGFkZHJlc3MiOiJqYXp6eWJ1cmdlckBxYS50ZWFtIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvZ2l2ZW5uYW1lIjoiamF6enkgYnVyZ2VyIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9ncm91cHNpZCI6IkFnZW50IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWdlbnQiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6Imphenp5YnVyZ2VyQHFhLnRlYW0iLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoie1wiVXNlcklkXCI6MzYzLFwiRnVsbE5hbWVcIjpcImphenp5IGJ1cmdlclwiLFwiRGVmYXVsdFdhbGxldElkXCI6XCI1MTQ5XCIsXCJXYWxsZXRDd