Skip to content

Instantly share code, notes, and snippets.

View leonid-ed's full-sized avatar

Leonid Edrenkin leonid-ed

View GitHub Profile
@leonid-ed
leonid-ed / bits_operation.h
Last active April 8, 2018 16:35
Macros for bit's manipulation: get bit, set bit, reset bit.
#define GET_BIT(X,N) ( ( (X) >> (N) ) & 1 )
#define SET_BIT(X,N) ( (X) | (1 << (N) ) )
#define RST_BIT(X,N) ( (X) & ~(1 << (N) ) )
@leonid-ed
leonid-ed / hexDump.c
Last active July 1, 2024 06:22
This function prints hex dump of memory specified as a pointer
/*
* This function prints hex dump of memory specified as a pointer.
* Reference: http://stackoverflow.com/questions/7775991/how-to-get-hexdump-of-a-structure-data
*/
#include <stdio.h>
void hexDump(char *desc, void *addr, int len)
{
int i;
unsigned char buff[17];
@leonid-ed
leonid-ed / ip_checksum.c
Created November 5, 2015 07:48
This function calculates a checksum of ip header
/*
* This function calculates a checksum of ip header.
* Reference: http://www.microhowto.info/howto/calculate_an_internet_protocol_checksum_in_c.html
*/
uint16_t ip_checksum(void* vdata, size_t length)
{
// Cast the data pointer to one that can be indexed.
char* data=(char*)vdata;
@leonid-ed
leonid-ed / h_guard_snippet.xml
Last active November 8, 2024 08:01 — forked from Muon/gist:2561013
C/C++ header guard snippet for Sublime Text 2/3
<snippet>
<content><![CDATA[
#ifndef ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g}
#define ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g}
$0
#endif // ${TM_FILEPATH/(([A-Za-z]+)\/src\/)|./\U(?1:$2_)\E/g}${TM_FILENAME/(([A-Z])([A-Z][a-z]))|(([a-z])([A-Z]))|([a-z])|(\.)/\U(?1:$2_$3)(?4:$5_$6)$7(?8:_)\E/g}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
@leonid-ed
leonid-ed / ifdebug_snippet.xml
Last active November 18, 2015 12:12
Sublime Text 2/3 snippet, what puts wrapper code for DEBUG preprocessor directive
<snippet>
<content><![CDATA[
#ifdef DEBUG
#endif // DEBUG
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>ifdebug</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.c++, source.c</scope>
</snippet>
@leonid-ed
leonid-ed / udp_to_local.c
Last active August 23, 2024 09:49
Examples of using raw sockets (c, linux, raw socket)
/*
An example of using raw sockets.
You can capture packets by tcpdump:
tcpdump -X -s0 -i lo -p udp
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@leonid-ed
leonid-ed / prepare-commit-msg
Last active April 28, 2016 08:00
.git/hooks/prepare-commit-msg showing latest 15 commit messages
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
#!/bin/bash
case "$2,$3" in
message,HEAD)
;;
*)
@leonid-ed
leonid-ed / C-make-multiline-macro.py
Created April 28, 2016 08:15
This is a Sublime Text 3 plugin that makes an adjusted multiline C-macro
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that makes an adjusted multiline C-macro.
# You should select some code and apply one of commands:
# view.run_command('make_multi_line_macro')
# view.run_command('unmake_multi_line_macro')
import sublime, sublime_plugin
@leonid-ed
leonid-ed / Text-item-list.py
Last active October 10, 2016 09:55
This is a Sublime Text 3 plugin that makes a numberred list.
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that makes and unmakes a numberred list.
# You should select text lines and apply one of commands:
# view.run_command('make_numberred_list')
# view.run_command('unmake_numberred_list')
import sublime, sublime_plugin
@leonid-ed
leonid-ed / clipboard-lines-copier.py
Last active March 16, 2017 08:14
Sublime Text 3 plugin that copies selected lines to the clipboard.
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that copies selected lines to the clipboard.
# You should select text lines and apply command:
# view.run_command('copy_lines_to_clipboard')
# view.run_command('copy_lines_to_clipboard', {"with_filename": True})
# view.run_command('copy_lines_to_clipboard', {"with_filename": True, "tabsize" : 4})