Skip to content

Instantly share code, notes, and snippets.

@withs
withs / vxx.v
Created May 10, 2022 19:57
Create Cxx classes with methods and members In V (poc)
// I have a special case where i need to create and give a c++ class with virtual methods,
// so i came up with this proof of concept.
// Known limitation:
// - accesing class member/methods from "this" is pertty impossible without storing the Cxx struct globaly
// - you can't pass struct methods since the struct ptr will overwrite the real "this" ptr
// use it:
// v -enable-globals -shared vxx.v (work well with autofree and prod)
// g++ vxx_class.cc
@withs
withs / forInRange.cc
Created December 7, 2021 14:18
poc of a simple implementation of python range bases loop in c++
// poc of a simple implementation of python range bases loop in c++
#include "iostream"
#include "vector"
template <typename T>
struct Range {
private:
std::vector<T> _vecRange = { };
@withs
withs / ClosestToPoint2D.cc
Created November 22, 2021 18:34
Get the closest point to a desired coordinate in a 2D space
#include "iostream"
#include "vector"
#include <math.h>
struct Vec3 {
float x,y,z;
};
template <class T>
Vec3 getClosest(std::vector<T> withPosVec, const Vec3 toPos) noexcept {
@withs
withs / vectorEnumerate.cc
Last active November 20, 2021 20:32
poc of a simple implementation of python list Enumerate in c++ (c++ vector enumerate)
#include "vector"
#include "cstdint"
// poc of a simple implementation of python list Enumerate in c++
// I choosed to use struct over std::tuple like in (python) because of the way to get the data, i prefer use name over numbers:
// elem.pos > std::get<0>(elem)
template<class T>
@withs
withs / palindrome.cc
Created October 15, 2021 18:33
palindrome.cc
#include "iostream"
#include "cstdint"
#include "chrono"
// Mac M1 (Apple clang version 13.0.0) 2.9s
// - Highest palindrome -> 98344389
// Ryzen 5 3600x (MinGW-W64 8.1.0) 1.6s
// - Highest palindrome -> 98344389
uint16_t intLen(uint64_t forInt) {
#include "cstdint"
uint16_t intLen(uint32_t forInt) {
uint64_t factor = 1;
uint16_t intLen;
for ( intLen = 0 ; (forInt / factor) != 0 ; intLen++ ) {
factor *= 10;
}
@withs
withs / find.cc
Created August 8, 2021 10:05
FInd in string in C String
#include "iostream"
int find(const char* word, const char* in, const int startAt = 0, int endAt = 0) {
int begin;
int verifyCount = 0;
int withSize = std::strlen(in);
// loop jusqu'a trouver une égalité du premier characthere de word et le char de l'index dans la loop
for ( int i = startAt; i <= ((endAt == 0) ? withSize:endAt); i++ ) {
// si le premier char de word et le char de l'index dans la loop sont égaux alors ont enrefistre l'index
// qui correspond a la position du premier char de word
@withs
withs / diceware_gen.swift
Last active June 5, 2021 09:40
Two functions wich generate dice combinations for diceware list
/*
Two functions wich generate dice combinations for diceware list, the firstone is oriented to be compact and the seconds oriented to be efficient
- results: withMaxInt: 6 and andMinLenght: 5 (Imac 2013, i5, swift 5.3.2)
Efficient done in -> 62.49544095993042 seconds
Compact done in -> 76.10342800617218 seconds
- results: withMaxInt: 6 and andMinLenght: 5 (Macbook air 2020, M1, swift 5.4)
Efficient done in -> 0.06685197353363037 seconds
Compact done in -> 0.23580491542816162 seconds
@withs
withs / conway.swift
Last active May 14, 2021 15:15
Simple script wich make the suite of conway
/*
Simple script wich make the suite of conway with a give limit (100 on this file)
with some info about the time :)
made on ipad pro in swift playground ^^
*/
import Foundation
let startTime = Date().timeIntervalSinceReferenceDate
@withs
withs / o_crosshair_indicators.lua
Last active May 10, 2021 10:43
crosshair indicators for Gamesense.pub
-- Shiba (8173)
local surface = require 'gamesense/surface'
local anti_aim = require 'gamesense/antiaim_funcs'
local screen_size = client.screen_size
local entity_get_prop = entity.get_prop
local entity_get_local_player = entity.get_local_player
local ui_get = ui.get
local ui_set = ui.set
local new_hotkey = ui.new_hotkey