This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [dependencies] | |
// actix-web = "4" | |
// serde = "1.0.202" | |
// serde_derive = "1.0.202" | |
use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; | |
use serde_derive::Deserialize; | |
#[derive(Deserialize)] | |
struct Info { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cargo.toml | |
// [dependencies] | |
// tokio = { version = "1", features = ["full"] } | |
// sqlx = { version = "0.7", features = ["runtime-tokio", "postgres"] } | |
use sqlx::postgres::PgPoolOptions; | |
use sqlx::{Column, Executor, Row, TypeInfo, ValueRef}; | |
struct Data { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
/// representing each term of the polynomial | |
struct Nomial { | |
coefficient: f64, | |
power: f64, | |
} | |
impl Nomial { | |
fn new(coefficient: f64, power: f64) -> Self { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** showip.c -- show IP addresses for a host given on the command line | |
** showip google.com | |
** Credit: Beej's Guide to Network Programming | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cargo add lettre | |
use lettre::address::Address; | |
use lettre::message::header::ContentType; | |
use lettre::message::Mailbox; | |
use lettre::transport::smtp::authentication::Credentials; | |
use lettre::{Message, SmtpTransport, Transport}; | |
struct EmailInfo { | |
credential_username: String, | |
credential_password: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package execBash | |
import ( | |
"bytes" | |
"os/exec" | |
) | |
func Execute(command string) (string, string, error) { | |
const ShellToUse = "bash" | |
var stdout bytes.Buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expected input: a sorted array | |
// Return: index n, such that array[n] <= target < array[n+1] | |
func binarySearch(array []uint64, target uint64) (int, error) { | |
var lower, upper = 0, len(array) - 1 | |
var preLower, preUpper = 0, len(array) - 1 | |
for array[lower] > target || array[lower+1] <= target { | |
if array[lower+1] == target { | |
return lower + 1, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"encoding/csv" | |
"log" | |
"os" | |
) | |
func readCsvFile(filePath string) [][]string { | |
f, err := os.Open(filePath) | |
if err != nil { | |
log.Fatal("Unable to read input file "+filePath, err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to run: go mod init <modname>; go tidy; go run . | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/davecgh/go-spew/spew" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/types.h> | |
ssize_t getline(char **restrict lineptr, size_t *restrict n, | |
FILE *restrict stream) { | |
register char c; |
NewerOlder