Skip to content

Instantly share code, notes, and snippets.

View cybertxt's full-sized avatar
🙈

cybertxt cybertxt

🙈
View GitHub Profile
#set connection data accordingly
source_host=localhost
source_port=6379
source_db=0
target_host=localhost
target_port=6379
target_db=1
#copy all keys without preserving ttl!
redis-cli -h $source_host -p $source_port -n $source_db keys \* | while read key;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@cybertxt
cybertxt / libuv-1-acceptor-multi-worker-server.c
Last active December 11, 2019 10:04
libuv works with one acceptor thread and multiple worker threads sample. This sample works ONLY on UNIX-like system.
#include <uv.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define WORKER_NUM 10
uv_thread_t worker_tid[WORKER_NUM];
uv_async_t async[WORKER_NUM];
uv_mutex_t mutex[WORKER_NUM];
@cybertxt
cybertxt / json_parser.cpp
Last active July 17, 2019 02:28
json parser
/**
# -*- coding:UTF-8 -*-
*/
#include "json_parser.hpp"
#include <assert.h>
static JO _g_jo_empty;
JO::JO()
@cybertxt
cybertxt / youtube-dl-examples.md
Created April 22, 2019 12:58
youtube-dl-examples

MP4

C:\youtube-dl.exe -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' 'https://www.youtube.com/watch?v=mgHxHIPcjbw' --proxy https://localhost:1080

@cybertxt
cybertxt / dec-ipstr
Last active November 14, 2018 16:28
Convert between network byte ordered decimal number and dot-delimited string in AWK
#!/usr/bin/awk -f
BEGIN {
dec = ARGV[1]
for (e = 3; e >= 0; e--) {
octet = int(dec / (256 ^ e))
dec -= octet * 256 ^ e
ip = octet delim ip
delim = "."
}
printf("%s\n", ip)
@cybertxt
cybertxt / .gdbinit
Created June 12, 2018 14:15 — forked from skyscribe/.gdbinit
GDB init file to print STL containers and data members
#
# STL GDB evaluators/views/utilities - 1.03
#
# The new GDB commands:
# are entirely non instrumental
# do not depend on any "inline"(s) - e.g. size(), [], etc
# are extremely tolerant to debugger settings
#
# This file should be "included" in .gdbinit as following:
# source stl-views.gdb or just paste it into your .gdbinit file
@cybertxt
cybertxt / write_speed_test.cpp
Last active September 20, 2017 02:55
fopen vs. freopen speed
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <time.h>
#include <assert.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
@cybertxt
cybertxt / simple_hash.c
Last active April 13, 2017 14:06
time31/bob hash methos
#include <stdint.h>
uint32_t time31_hash_bin(const void* data, uint32_t length)
{
uint32_t hash = 0;
const uint8_t* p = (const uint8_t*)data;
const uint8_t* pend = p + length;
for(; p < pend; ++p)
hash = (hash<<5) - hash + *p;
return hash;