Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@shintakezou
shintakezou / systemd-240-my.patch
Last active October 19, 2019 22:12
A patch for Ubuntu 19.04 (disco)'s systemd v240 issue with the memlock (systemd 240-6ubuntu5.7)
--- a/src/core/main.c 2019-10-19 18:11:23.000000000 +0200
+++ b/src/core/main.c 2019-10-19 17:41:36.465000943 +0200
@@ -1265,6 +1265,7 @@
}
static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
+ struct rlimit new_rlimit;
int r, nr;
assert(saved_rlimit);
@shintakezou
shintakezou / Canoa.java
Last active May 20, 2019 11:56
Run two canoes to solve Italian's magazine puzzle "Quesito con la Susi n. 959"
class Canoa
{
private double pos; // m
private double vel; // m/s
public Canoa(double init_pos, double v) {
this.vel = v;
this.pos = init_pos;
}
@shintakezou
shintakezou / multidyndispatch.cpp
Created April 16, 2019 21:05
Dynamic dispatch not just on the first argument (at least C++14)
// see https://www.reddit.com/r/cpp_questions/comments/afp4ae/dynamic_argumentbased_dispatch_will_it_ever_be/eeh8qe7/
// credits to https://www.reddit.com/user/alfps
// I've modified it so that it can be compiled with a C++14 compliant compiler, plus minor style
// modifications, e.g., I've changed the syntax auto x()->ReturnValue in function declaration and defines,
// since there's no point in using it.
#include <array> // std::array
#include <functional> // std::function
#include <iostream>
#include <map> // std::map
@shintakezou
shintakezou / counter.ads
Created April 14, 2019 19:00
Nested functions/procedures in Ada, and count unique according to a certain idea of equality.
package Counting is
type Element is
record
S : String (1 .. 3);
E1 : Integer;
E2 : Integer;
end record;
type Elements is array (Positive range <>) of Element;
module Counter
(Element(..),
countUnique,
countUnique2) where
data Element = Element { s :: String,
e1 :: Int,
e2 :: Int } deriving (Show, Eq)
@shintakezou
shintakezou / counter2.f03
Created April 14, 2019 16:50
Nested functions in Fortran (2003, 2008…)
module counter2
implicit none
type element
character(len=16) :: s
integer :: e1, e2
end type element
contains
function count_unique(s) result(c)
@shintakezou
shintakezou / Element.cpp
Created April 14, 2019 16:22
Lambda used as nested functions.
#include "Element.hpp"
#include <vector>
#include <string>
size_t count_uniques(const std::vector<SElement> v)
{
size_t c = 0;
bool found;
@shintakezou
shintakezou / elements.c
Created April 14, 2019 15:51
Couting unique elements, with a peculiar definition of equality.
#include "elements.h"
#include <stddef.h>
#include <stdbool.h>
static int compare(const element *a, const element *b)
{
if (a->e2 == b->e2)
return 0;
else if (a->e1 != b->e1)
@shintakezou
shintakezou / dyndis.hs
Created January 13, 2019 21:35
tests of "dynamic overloading" (or alike) in several languages
-- interpreter of + and .
data StackEl = Onum Integer | Ostr String
instance Show StackEl where
show (Onum a) = show a
show (Ostr s) = "\"" ++ s ++ "\""
plus (Onum a) (Onum b) = Onum $ a+b
plus (Onum a) (Ostr b) = Ostr $ (show a) ++ b
@shintakezou
shintakezou / dynamic_dispatch.cpp
Created January 12, 2019 21:46
Dynamic overloading simple poc test (dynamic dispatching)
#include <iostream>
// likely you'd like to use this someway; instead, this code
// simply ignores and accepts memory leaks.
//#include <memory>
#include <string>
#include <stack>
#include <sstream>