Skip to content

Instantly share code, notes, and snippets.

View piusayowale's full-sized avatar

OGUNLEYE AYOWALE piusayowale

  • Lagos, Nigeria
View GitHub Profile
@piusayowale
piusayowale / boost-asio-event.cpp
Created January 12, 2023 19:38
pooling event with boost.asio
// prac.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <boost/asio.hpp>
#include <thread>
#include <chrono>
std::chrono::seconds getsecondsPt() {
auto st = std::chrono::high_resolution_clock::now().time_since_epoch();
@piusayowale
piusayowale / listvckgport.py
Created January 10, 2023 14:26
get list of packages and their descriptions
import os
import json
import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
def save(dat):
with open('dump', 'a') as file:
file.write(dat)
// sdlCircle.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <SDL2/SDL.h>
#include "tinysplinecxx.h"
struct Point {
double x;
double y;
@piusayowale
piusayowale / getuniquepartition.cpp
Created September 25, 2022 09:05
print all unique partition of a number
void printArray(int p[], int n)
{
for (int i = 0; i < n; i++)
cout << p[i] << " ";
cout << endl;
}
void printAllUniqueParts(int n)
@piusayowale
piusayowale / integer_partition.cpp
Created September 25, 2022 09:00
integer partition with at most k part problem
int Ipan(int num, int k){
int table[num][k];
for(int j = 1; j <= k; j++){
table[0][j] = 1;
table[1][j] = 1;
}
for(int i = 2; i <= num; i++){
table[i][1] = 1;
for(int j = 2; j <= i; j++){
int longestPalindrome(string s) {
map<char, int> count;
for (char c: s){
count[c]++;
}
int ans = 0;
for (auto v: count) {
ans += v.second / 2 * 2;
if (ans % 2 == 0 && v.second % 2 == 1)
ans++;
int utopianTree(int n) {
int res = 0;
int rem = 0;
for(int i = 0; i <= n; i++){
if(rem == 0 && i > 0){
res = res * 2;
}else{
res = res + 1;
}
int mod = i % 2;
@piusayowale
piusayowale / wordIncamelCaseCounter.cpp
Created September 5, 2022 13:20
simple problem of counting words in a camel case
int camelcase(string s) {
int counter = 0;
for(int i = 0; i < s.size(); i++){
if(isupper(s[i])){
counter++;
}
}
return counter + 1;
@piusayowale
piusayowale / reducedstring.cpp
Created September 5, 2022 13:09
super reduced string
string superReducedString(string s) {
string temp;
int index = 0;
for(int i = 0; index < s.size(); i++){
if(s[index] == s[index+1]){
index = index + 2;
}
else {
if(!temp.empty()){
if(*(temp.end() -1) != s[index]){
@piusayowale
piusayowale / height.cpp
Created September 2, 2022 16:19
height of a binary tree
int height(Node* root) {
if (root == NULL)
return -1;
else
{
/* compute the depth of each subtree */
int lefth = height(root->left);
int righth = height(root->right);
/* use the larger one */