Skip to content

Instantly share code, notes, and snippets.

@AntonioCS
AntonioCS / bcmake.bat
Last active Jul 1, 2020
Small bat file to create basic project. Will create src/ dir if not present (with dummy code). Will create tests/ folder if not present (with dummy test code). Will create build/ folder (if present with a .sln file ask if you want to delete). Check if there is a CMakeLists.txt and if there isn't create a generic one.
View bcmake.bat
@echo off
@setlocal EnableExtensions EnableDelayedExpansion
:: This batch file will try to generate a minimalist project
:: It will create a src folder with a small cpp file^
:: It will create a test folder with some mock test files for catch2/catch
:: It will also ask if you want to enable testing
:: If a solution already exists (in the build folder) it will ask if you want to remove it and rebuild
:: NOTE: Run this in admin mode if it doesn't work
View PHP debugger cli
export PHP_IDE_CONFIG=\"serverName=${phpstorm_server_config_name}\" && \
php \
-dxdebug.remote_host=${xdebug_remote_host} \
-dxdebug.remote_port=${xdebug_remote_port} \
-dxdebug.idekey=${xdebug_idekey} \
-dxdebug.remote_enable=${xdebug_remote_enable} \
-dxdebug.remote_mode=${xdebug_remote_mode} \
-dxdebug.remote_autostart=${xdebug_remote_autostart} \
-dxdebug.remote_connect_back=${xdebug_remote_connect_back} \
-dxdebug.remote_log=${xdebug_remote_log} \
View format php logs with strack traces
tail -f -v logdir/*.log | sed -E 's/([^\n]#[0-9]+\s)/\n\1/g'
View flip_unordered_map.cpp
#include <iostream>
#include <unordered_map>
#include <string>
template <typename T1, typename T2>
std::unordered_map<T2, T1> flip(std::unordered_map<T1, T2>& m) {
std::unordered_map<T2, T1> result;
for (auto&& [key, value] : m) {
result.emplace(value, key);
View getPrivateParentProperties.php
<?php
class Pappi {
private $prop = "default value";
}
class Child extends Pappi {
View permutations_example.php
<?php
//https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
function swap(string &$str, int $i, int $ii) : void {
$tmp = $str[$i];
$str[$i] = $str[$ii];
$str[$ii] = $tmp;
}
function permute(string $str, int $l, int $r, array &$result) : void {
@AntonioCS
AntonioCS / regex_match_all.cpp
Created Oct 29, 2019
Using c++ regex to create a match all function which returns the matched element and the position
View regex_match_all.cpp
#include <iostream>
#include <string>
#include <vector>
#include <regex>
auto match_all(std::string input, const std::string& pattern) noexcept {
std::vector<std::pair<std::string, int>> matches{};
try {
const std::regex self_regex(pattern);//, std::regex_constants::ECMAScript | std::regex_constants::icase);
@AntonioCS
AntonioCS / Makefile
Last active Nov 21, 2019
Self documenting makefile template for docker (php)
View Makefile
.DEFAULT_GOAL := help
.PHONY: help
compose_file_path = ./docker/docker-compose.yml
dc = docker-compose --file $(compose_file_path)
service_php = php_fpm
phpstorm_server_config_name = my-server-name
service_redis = redis
xdebug_remote_host=host.docker.internal
xdebug_remote_port=10000
xdebug_idekey=PHPSTORM
@AntonioCS
AntonioCS / main.cpp
Created Aug 21, 2019
Using regex in C++ to transform a string into JSON
View main.cpp
/**
This should transform the string:
- name=Maria, grades-90,age/25?university-UCL,surname=Hill,grades//85,graduates=5%ID=356231, graduates-7,grades=78//graduates=3
Into:
{
"output":{
"university":"UCL",
"students":{
"name":"Maria",
View solution.cmd
@echo off
set __SOURCE_PATH=%~dp0
set __SOURCE_PATH=%__SOURCE_PATH:~0,-1%
for /f %%i in ('where vcpkg.exe') do (
set __SCRIPT_PATH=%%~dpiscripts
goto :script_found
)
echo Could not find executable: vcpkg.exe
You can’t perform that action at this time.