Skip to content

Instantly share code, notes, and snippets.

View martinomburajr's full-sized avatar
🦆
Relentlessly pursuing those carbs

Martin Ombura Jr. martinomburajr

🦆
Relentlessly pursuing those carbs
View GitHub Profile
@martinomburajr
martinomburajr / deployinstance.go
Created May 22, 2019 10:32
Create's a compute engine virtual machine, then each call either starts or stops the VM. This code runs on Cloud Functions
package cloudfunctions
import (
"context"
"fmt"
"google.golang.org/api/compute/v1"
"log"
"net/http"
"os"
)
@martinomburajr
martinomburajr / connect-unix-syscall.cpp
Created May 20, 2019 05:09
Connect, Accept and Listen Syscalls
#include <sys/types.h>
#include <sys/socket.h>
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
@martinomburajr
martinomburajr / listen-socket-unix-api-call.cpp
Created May 20, 2019 05:02
Listen to a socket API Call UNIX
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
int listen(int sockfd, int backlog);
@martinomburajr
martinomburajr / accept-socket-unix-api-call.cpp
Created May 20, 2019 05:01
Accept Socket API call Unix
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
@martinomburajr
martinomburajr / golang-rawsocket-syscall.go
Last active May 20, 2019 11:06
Creating a socket in Golang
// This unimplemnted function is found in the syscall/syscall_linx_386.go file and is referenced by the socket function below.
// It is implemented in the syscall/asm_linux_s390x.s file
func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
@martinomburajr
martinomburajr / socket-api-bind-windows.c
Last active May 18, 2019 05:16
Socket API Bind methods in both UNIX and Windows Systems
// Unix implementation of bind() system call
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
@martinomburajr
martinomburajr / socket-api-unix.c
Last active May 18, 2019 04:49
Socket API for Unix and Windows
// Unix implementation of socket() system call
int socket(int domain, int type, int protocol);
@martinomburajr
martinomburajr / net-conn-struct.go
Created May 14, 2019 05:13
The net conn struct that has a pointer to a network file descriptor
type conn struct {
fd *netFD
}
@martinomburajr
martinomburajr / net-conn-close.go
Last active May 14, 2019 05:08
The Closer implementation of net.Conn
// Close closes the connection.
func (c *conn) Close() error {
if !c.ok() {
return syscall.EINVAL
}
err := c.fd.Close()
if err != nil {
err = &OpError{
Op: "close",
Net: c.fd.net,
@martinomburajr
martinomburajr / net-conn-write.go
Last active May 14, 2019 05:09
The Writer implementation of net.Conn
// Write implements the Conn Write method.
func (c *conn) Write(b []byte) (int, error) {
if !c.ok() {
return 0, syscall.EINVAL
}
n, err := c.fd.Write(b)
if err != nil {
err = &OpError{
Op: "write",
Net: c.fd.net,