Skip to content

Instantly share code, notes, and snippets.

@Junch
Junch / gist:9ed95e394164703a6bb9c732962f8f00
Created January 4, 2019 07:49 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@Junch
Junch / getopts.bash
Last active October 26, 2018 07:53
bash getopts
#!/bin/bash
######################################################################
#This is an example of using getopts in Bash. It also contains some
#other bits of code I find useful.
#Author: Linerd
#Website: http://tuxtweaks.com/
#Copyright 2014
#License: Creative Commons Attribution-ShareAlike 4.0
#http://creativecommons.org/licenses/by-sa/4.0/legalcode
@Junch
Junch / bench.cpp
Created October 16, 2018 09:18
c++ high_resolution_clock
using std::chrono::high_resolution_clock;
auto start = high_resolution_clock::now();
// do work ...
auto delta = high_resolution_clock::now() - start;
auto delta_d = duration_cast<duration<double>>(delta).count();
cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl;
@Junch
Junch / function.cpp
Created October 10, 2018 10:06
std::function implementation
/******************************************************************************
https://stackoverflow.com/questions/18453145/how-is-stdfunction-implemented
*******************************************************************************/
#include <iostream>
#include <memory>
template <typename T>
@Junch
Junch / read_file.cpp
Created September 18, 2018 07:35
read a whole binary file to buffer
// https://bytefreaks.net/programming-2/c/cc-full-example-of-reading-a-whole-binary-file-to-buffer
struct binary_data_t
{
long size;
void *data;
binary_data_t() : size(0), data(nullptr) {}
~binary_data_t() { delete[] data; }
};
@Junch
Junch / grep_ag_sed.sh
Last active April 12, 2021 07:47
Replace a string to another string in macOS
grep -rl --include=\*.java "boolean moreResults" . | xargs sed -i '' 's/boolean moreResults/boolean isFinishedSearching, boolean isMoreResults/g'
ag -l moreResults -G ".m" | xargs sed -i '' 's/moreResults:(BOOL)moreResults/isFinishedSearching:(BOOL)isFinishedSearching isMoreResults:(BOOL)isMoreResults/g'
noglob find . -type f -name SearchBoxPanel.* | xargs sed -i '' 's/bool moreResults/bool isFinishedSearching, bool isMoreResults/g'
find . -name AndroidABEquivalenceSearchQuery.cpp | xargs subl
@Junch
Junch / readme.md
Last active August 9, 2018 07:16
Run clang-tidy to modernize the code
find . -name *.cpp | xargs clang-tidy -header-filter='Spark*.*' -checks='-*,modernize-*,readability-*' -fix
@Junch
Junch / mergejson.sh
Last active October 23, 2018 01:58
Script to generate the compile_commands.json
#!/bin/bash
# Refer to
# 1. http://blog.51cto.com/liveforlinux/689382
# 2. https://sarcasm.github.io/notes/dev/compilation-database.html
# 3. https://unix.stackexchange.com/questions/38172/switching-to-zsh-are-all-bash-scripts-compatible-with-zsh/38173
# 在scons文件中,添加 env.Append(CCFLAGS=['-MJ', '${TARGET}.json'])
find ./out/macosx-10.13-x86_64-rel/obj-static/src/ -name "*.o.json" | xargs sed -e '1s/^/[\'$'\n/' -e '$s/,$/\'$'\n]/' > compile_commands.json
@Junch
Junch / conversion.cpp
Created July 17, 2018 08:15 — forked from pezy/conversion.cpp
Encoding Conversion In C++
// Convert a wide Unicode string to an UTF8 string
std::string utf8_encode(const std::wstring &wstr)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
// Convert an UTF8 string to a wide Unicode String
@Junch
Junch / reggetvalue.cpp
Last active July 13, 2018 05:36
Read the registry
#include <windows.h>
#include <iostream>
#pragma comment(lib, "advapi32.lib")
int main()
{
char value[255];
DWORD BufferSize = sizeof(value);
RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "SystemRoot", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);