Skip to content

Instantly share code, notes, and snippets.

View halloweeks's full-sized avatar
💭
I may be slow to respond.

Hallo Weeks halloweeks

💭
I may be slow to respond.
View GitHub Profile
@oleksiiBobko
oleksiiBobko / tcp_server.c
Last active November 20, 2024 09:31
Simple socket server in C using threads (pthread library) Compiles on linux
/*
C socket server example, handles multiple clients using threads
Compile
gcc server.c -lpthread -o server
*/
#include<stdio.h>
#include<string.h> //strlen
#include<stdlib.h> //strlen
#include<sys/socket.h>
@meritozh
meritozh / exec.cpp
Created April 5, 2016 07:12
use c++ to execute a command and get the output of command. It only grab stdout. Use perror or add "2>&1" for grabbing stderr.
#include <iostream>
#include <cstdarg>
#include <string>
#include <fstream>
#include <memory>
#include <cstdio>
std::string exec(const char* cmd) {
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) return "ERROR";
@gomons
gomons / zlib_strings.cpp
Last active March 6, 2023 17:57
Compressing STL Strings with zlib
// Copyright 2007 Timo Bingmann <tb@panthema.net>
// Distributed under the Boost Software License, Version 1.0.
// (See http://www.boost.org/LICENSE_1_0.txt)
//
// Original link http://panthema.net/2007/0328-ZLibString.html
#include <string>
#include <stdexcept>
#include <iostream>
#include <iomanip>
@halloweeks
halloweeks / log.txt
Last active May 13, 2024 03:02
c++ zlib compress decompress string
# compile
g++ zlib.cpp -o zz -lz
# run
root@localhost:~# ./zz
Orignal string size: 43
Original string: halloweeks halloweeks halloweeks halloweeks
--------------------
Compressed string size: 22
@halloweeks
halloweeks / main.cpp
Last active January 16, 2023 12:49
c++ url decoder
#include <iostream>
#include <stdlib.h>
#include <string>
std::string url_decode(char *url) {
std::string temp, output;
char ch;
for (unsigned int index = 0; index < strlen(url)+1; index++) {
if (url[index] == '%') {
temp += url[index+1];