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
/* -*- compile-command: "gcc -Wall -pedantic -g3 server.c -o server" -*- */ | |
/** | |
TCP server implementation | |
1. Create a TCP socket. | |
2. bind(), Bind the socket to server address. | |
3. listen(), Put the server socket in a passive mode, it waits for the client to make a connection | |
4. accept(), Connection is established between client and server, ready to transfer data. | |
5. go back to Step 3. |
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
/* -*- compile-command: "gcc -Wall -pedantic -g3 client.c -o client" -*- */ | |
/** | |
TCP client implementation | |
1. Create TCP socket. | |
2. connect() Connect newly created client socket to server. | |
**/ | |
#include <stdio.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
func twoSum(nums []int, target int) []int { | |
var tempDict = make(map[int]int) | |
for key, value := range nums { | |
if _, ok := tempDict[value]; ok{ | |
return []int{tempDict[value], key} | |
} | |
tempDict[target-value] = key | |
} | |
return []int{} | |
} |
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
/* | |
Algorithm | |
- if a node is NULL or equal p or q, we return it | |
- if not, we traverse the left and right subtree until we return a node, assigning to bool value RetLeft or RetRight | |
- Then we check if we have to return the node (RetLeft and RetRight are both != NULL), or only left or right | |
- The LCA is of course the node with RetLeft AND RetRight != NULL | |
*? | |
/** | |
* Definition for a binary tree node. |
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
/** | |
Algorithm | |
- Start traversing the tree from the root node. | |
- If both p and q are < root, then continue to left subtree and starting step 1. | |
- If both p and q are > root, then continue to right subtree and starting step 1. | |
- If both step 2 and step 3 are not true, we have found the LCA for p and q, and we return it | |
*/ | |
/** |
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 main | |
import ( | |
"fmt" | |
"time" | |
"strconv" | |
"strings" | |
) | |
func track(msg string) (string, time.Time) { |
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
/* -*- compile-command: "gcc -Wall -pedantic -g3 dir_cleaner.c -o dir_cleaner" -*- */ | |
#define _XOPEN_SOURCE 500 | |
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
#include <ftw.h> | |
#include <dirent.h> | |
#include <unistd.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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <uv.h> | |
//based on https://gist.githubusercontent.com/snatchev/5255976/ | |
//raw/8392c42d719bb775053036e32b21affdf932c1b7/libuv-tcp-client.c | |
//which was based on libuv 0.1, there is considerable difference there. | |
static void on_close(uv_handle_t* handle); | |
static void on_connect(uv_connect_t* req, int status); | |
static void on_write(uv_write_t* req, int status); |
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
/** | |
* Take the URL of remote pcap from command line and download the file to disk | |
* It check if the extension is allowed (pcap-cap-pcapng) | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <curl/curl.h> | |
#define FILENAME_LEN 1000 |
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
<?php | |
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | |
socket_bind($sock, '0.0.0.0', 10000); | |
for (;;) { | |
socket_recvfrom($sock, $message, 1024, 0, $ip, $port); | |
$reply = str_rot13($message); | |
socket_sendto($sock, $reply, strlen($reply), 0, $ip, $port); | |
} |
NewerOlder