Skip to content

Instantly share code, notes, and snippets.

View shazni's full-sized avatar

Shazni shazni

View GitHub Profile
#include <iostream>
#include <string>
#include <memory>
#include "libgointeropcode.h"
class Message {
public:
Message() {}
void setMsg(std::string msg) {
@shazni
shazni / MyGoInteropCode.go
Created August 11, 2023 05:27
MyGoInteropCode.go with callback to C functions
package main
/*
#include <stdlib.h>
#include <stdbool.h>
typedef const char* (*get_message_body_callback)(long long);
static const char* getMessageBodyHelper(get_message_body_callback getMessgeBodyCb,
long long contextHandle) {
return getMessgeBodyCb(contextHandle);
@shazni
shazni / MyFactorialGoCode.go
Created August 3, 2023 12:16
MyFactorialGoCode.go
package main
import "C"
func calcFactorial(n uint64) (result uint64) {
if n > 0 {
result = n * calcFactorial(n-1)
return result
}
return 1
@shazni
shazni / ChatWebsocketService.bal
Last active May 9, 2023 04:15
Websocket service implementation in Ballerina
import ballerina/io;
import ballerina/websocket;
map<int> userMap = {};
map<websocket:Caller> connectionMap = {};
isolated int lastUserId = 0;
service / on new websocket:Listener(9876) {
resource function get .() returns websocket:Service {
return new ChatService();
@shazni
shazni / main.go
Created March 9, 2023 10:20
Go source file that uses the C library
package main
// #cgo CFLAGS: -g -Wall
// #cgo CFLAGS: -I./calcClib
// #cgo LDFLAGS: -L./calcClib -lcalc_color_print
// #include <stdlib.h>
// #include "calcClib/calc_color_print.h"
import "C"
import (
@shazni
shazni / calc_color_print.c
Created March 9, 2023 10:15
Definition of factorial and color_print functions
#include <stdio.h>
#include <string.h>
#include "calc_color_print.h"
int factorial(int num) {
if(num > 1) {
return num * factorial(num - 1);
}
return 1;
@shazni
shazni / calc_color_print.h
Created March 9, 2023 09:29
C Header file with two function declarations
#ifndef _COLOR_PRINT_H
#define _COLOR_PRINT_H
int factorial(int number);
void color_print(const char* color, const char* message);
#endif
@shazni
shazni / models.py
Last active February 5, 2022 12:56
Django Model Definition
from django.db import models
# Create your models here.
class Product(models.Model):
name = models.CharField(max_length=30)
product_category = models.CharField(max_length=30, blank=True, default='')
created_date = models.DateTimeField()
available_items = models.IntegerField(blank=True, null=True)
@shazni
shazni / ariadne_helloworld.py
Created March 10, 2021 11:17
GraphQL Hello World with Ariadne
from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
# Define types using Schema Definition Language (https://graphql.org/learn/schema/)
# Wrapping string in gql function provides validation and better error traceback
type_defs = gql("""
type Query {
hello: String!
}
""")
@shazni
shazni / model.py
Created March 1, 2021 16:35
Book Model
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=30)
description = models.TextField(blank=True)
publisher_book_url = models.URLField()
released_on = models.DateTimeField(auto_now_add=True)
posted_user = models.ForeignKey(get_user_model(), null=True, on_delete=models.CASCADE)