Skip to content

Instantly share code, notes, and snippets.

@tjhv
tjhv / echoserver.c
Created February 17, 2018 05:29
Old snippet from back in the day.
/*
* @Author tjhv
* @Version 1.0.1
* @year 2009
**/
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
@tjhv
tjhv / winsockircbot.c
Created February 17, 2018 05:33
Old snippet from the beginning.
//feb 1 2009
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winsock.h>
int main(int argc, char * argv[])
{
int eid;
@tjhv
tjhv / ircbot.c
Created February 17, 2018 05:34
Old snippet from the beginning.
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define DSTADDR "darklite.be.eu.SwiftIRC.net"
#define DSTPORT 6667
@tjhv
tjhv / winsockserver.cpp
Created February 17, 2018 05:35
Old snippet from the beginning.
#include <iostream>
#include <winsock.h>
#define PORT 7096
#pragma comment(lib, "wsock32.lib")
int main(void)
{
std::cout << "Start of program." << std::endl;
WORD wVersion = MAKEWORD(1, 1);
WSADATA wsaData;
extension String
{
func character(at index: Int) -> Character?
{
guard index <= self.count && index >= -self.count && index != 0 else {
return nil
}
return Array(self)[(index > 0 ? index - 1 : self.count + index)]
}
#include <stdio.h>
int sum0(int n)
{
return n > 0 ? sum0(n - 1) + n : 0;
}
int sum1(int n)
{
return n > 0 ? sum1(n / 10) + (n % 10) : 0;
extension Dictionary where Value: Equatable
{
func allKeys(for value: Value) -> [Key]
{
return self.enumerated().compactMap {
$0.element.value == value ? $0.element.key : nil
}
}
}