Skip to content

Instantly share code, notes, and snippets.

View samolisov's full-sized avatar

Pavel Samolysov samolisov

  • Huawei
  • Moscow/Russia
View GitHub Profile
@samolisov
samolisov / clang_static_analysis.cmake
Last active December 20, 2021 11:05
CMake: add target for invoking Clang Static Analyzer
# The solution is based upon this answer:
# https://stackoverflow.com/questions/19050461/cmake-add-target-for-invoking-clang-analyzer
function(add_clang_static_analysis target)
get_target_property(SRCs ${target} SOURCES)
add_library(${target}_analyze OBJECT EXCLUDE_FROM_ALL ${SRCs})
if (MSVC)
list(APPEND ANALYZER_OPTIONS --analyze)
list(APPEND ANALYZER_OPTIONS "SHELL:/clang:-Xanalyzer /clang:-analyzer-opt-analyze-headers")
list(APPEND ANALYZER_OPTIONS "SHELL:/clang:-Xanalyzer /clang:-analyzer-output=html")
# see output in <build/<file>.plist directories
@samolisov
samolisov / json_serializer_demo.cpp
Created July 23, 2019 12:09
A short demo how to use a recursive std::variant
#include <iostream>
#include <map>
#include <string>
#include <sstream>
#include <variant>
#include <vector>
struct JSONValue;
class JSONStringVisitor;
class JSONSerializer;
@samolisov
samolisov / btree.py
Created April 22, 2019 14:08
A BTree implementation on python
import bisect
# See Cormen et al, chapter 18 B-Trees. The implementation uses the 'bisect' module to implement
# a binary search (O(lg n)) through nodes.
def main():
def allocme():
nonlocal blocks
idx = len(blocks)
blocks.append(None)
@samolisov
samolisov / huffman_code.py
Last active March 25, 2019 11:48
Cormen et al, 16.3 Huffman code (test for German)
import heapq
def main():
freqmap = {'a':45, 'b':13, 'c':12, 'd':16, 'e':9, 'f':5}
char_to_code = huffman(freqmap)
print(char_to_code)
print(invert_dictionary(char_to_code))
print()
# see https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_other_languages
package psamolysov.algo.intro.maxsubarray;
import java.util.LinkedHashMap;
import java.util.Map;
public class LongestLinearSubstringer {
public static String findLongestKCharSubstring(String str, int k) {
if (str == null || str.length() < k) {
return str;
@samolisov
samolisov / create-a-large-jms-cluster-domain.py
Created October 31, 2017 14:48
Usable WLST scripts for every day WebLogic Application Server administration
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
from wlstModule import *#@UnusedWildImport
def configureCluster(clusterName, isUnicast):
cluster = getMBean('/Clusters/' + clusterName)
if cluster == None:
print 'Creating cluster ' + clusterName
cluster = create(clusterName, 'Cluster')