Skip to content

Instantly share code, notes, and snippets.

View shelterz's full-sized avatar
🎯
Focusing

ZhangCongjing shelterz

🎯
Focusing
  • Sinosdx
  • Shanghai
View GitHub Profile
@shelterz
shelterz / http_post_form.c
Created July 2, 2020 11:14
Use http post with form-data body to upload file to web server
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@shelterz
shelterz / timer_test.c
Created June 5, 2020 06:21
Linux System timer test case
#include <stdio.h>
#include <unistd.h>
#include <sys/timerfd.h>
#include <sys/epoll.h>
#define MAX_EVENTS 10
int main(int argc, char **argv)
{
int timerfd;
#include <iostream>
#include <string>
#include <memory>
#include <limits>
#include <stdexcept>
#include <openssl/evp.h>
#include <openssl/rand.h>
static const unsigned int KEY_SIZE = 32;
@shelterz
shelterz / SSL-certs-OSX.md
Created September 5, 2019 09:02 — forked from croxton/SSL-certs-OSX.md
Generate ssl certificates with Subject Alt Names

Generate ssl certificates with Subject Alt Names on OSX

Open ssl.conf in a text editor.

Edit the domain(s) listed under the [alt_names] section so that they match the local domain name you want to use for your project, e.g.

DNS.1   = my-project.dev

Additional FQDNs can be added if required:

@shelterz
shelterz / pthread_cond.c
Created August 26, 2019 07:58
pthread condition broadcast
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
pthread_cond_t cond;
pthread_mutex_t lock;
void *t0(void *param)
{
pthread_mutex_lock(&lock);
@shelterz
shelterz / pthread_barrier.c
Created August 26, 2019 07:06
pthread barrier usage example
#include <stdio.h>
#include <pthread.h>
#define THREAD_NUMS 4
pthread_barrier_t barrier;
void *t0(void *param)
{
pthread_barrier_wait(&barrier);
printf("t0 ready\n");
@shelterz
shelterz / producer_consumer.c
Last active August 23, 2019 09:15
producer consumer problem
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#define BUFFER_SIZE 10
sem_t fill_count, empty_count;
pthread_mutex_t lock;
int p;
@shelterz
shelterz / ip_forward.md
Created May 24, 2019 05:42 — forked from tzermias/ip_forward.md
Forward traffic from wlan0 to eth0 interface

Forward traffic from a laptop's eth0 to wlan0

###To laptop

Specify an IP address to eth0 (here 192.168.56.1)

sudo ifconfig eth0 192.168.56.1 netmask 255.255.255.0
@shelterz
shelterz / fanotify-example.c
Created April 12, 2019 08:20 — forked from jaypeche/fanotify-example.c
fanotify example
/*
* File: fanotify-example.c
* Date: Fri Nov 15 14:55:49 2013
* Author: Aleksander Morgado <aleksander@lanedo.com>
*
* A simple tester of fanotify in the Linux kernel.
*
* This program is released in the Public Domain.
*
* Compile with: