Skip to content

Instantly share code, notes, and snippets.

View nyrahul's full-sized avatar
🐞

Rahul Jadhav nyrahul

🐞
View GitHub Profile
@nyrahul
nyrahul / clang-format-config
Last active September 11, 2018 04:08
My clang-format
---
Language: Cpp
# BasedOnStyle: LLVM-Modified-by-RJ
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
Verifying my Blockstack ID is secured with the address 1FhDaxSAbL7yf78wAgtZshqvt7EJsC4mfx https://explorer.blockstack.org/address/1FhDaxSAbL7yf78wAgtZshqvt7EJsC4mfx
@nyrahul
nyrahul / kernel.config
Last active December 12, 2020 17:28
My tailored linux kernel config file for Huawei Matebook X Pro 2018 Model. Enables Wacom tablet support.
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 4.18.7 Kernel Configuration
#
#
# Compiler: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
#
CONFIG_64BIT=y
CONFIG_X86_64=y
Iptables ip/port range spec:
Multiple individual ports:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 110,143,993,955 -j MARK --set-mark 13
Port Range:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1024:3000 -j MARK --set-mark 13
Multiple Port ranges:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1000:2000,3000:4000 -j MARK --set-mark 13
@nyrahul
nyrahul / interesting c one-liners
Last active June 10, 2020 02:18
cpu efficient c one-liners
bool isPowOf2(val)
{
return val && !( val & ( val - 1));
// val && is required so that val=0 is handled. 0 is not the pow of 2
}
/* increment val only if MAX_UINT val not reached. Use-case: for stats incr, you dont want the val to cycle */
#define STAT(S) (S) += (!!(S ^ 0xffffffff)) // S will incr by 1 only till it reach 0xffffffff
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalVariableCase, value: camelBack }
@nyrahul
nyrahul / Makefile
Last active April 10, 2019 10:39
Makefile trick: disable verbose compilation .. enable verbose only if 'make V=1'
CC=gcc
AR=ar
V = 0
ACTUAL_CC := $(CC)
CC_0 = @echo "CC [$<]"; $(ACTUAL_CC)
CC_1 = $(ACTUAL_CC)
CC = $(CC_$(V))
ACTUAL_AR := $(AR)
@nyrahul
nyrahul / perf-record.cmd
Created April 24, 2019 06:25
Perf record with single symbol reporting from multiple threads
perf record --call-graph dwarf -p PID
perf report --call-graph=graph,0.001,calle,function,percent --sort=symbol
perf report --call-graph=graph,0.001,calle,function,count --sort=symbol
// Example code which shows how to compare the two typedefs for size equivalency.
#define CONCAT_(a,b) a##b
#define CONCAT(a,b) CONCAT_(a, b)
#define STATIC_ASSERT(e) \
; enum { CONCAT(assert_line_, __LINE__) = 1/(int)(!!(e)) }
/* Note that ; is needed before enum if the STATIC_ASSERT is added right after case or label statement */
/* Note that multiple CONCATs are needed so that __LINE__ could be expanded .. Thus you can now have multiple STATIC_ASSERTs in the same code block */