Skip to content

Instantly share code, notes, and snippets.

View Denommus's full-sized avatar

Yuri Albuquerque Denommus

  • Brick Abode
  • Florianópolis, SC, Brazil
View GitHub Profile
@Denommus
Denommus / factorial.lisp
Last active February 4, 2025 14:49
A simple tail-recursive factorial example
(defun factorial (number)
(labels ((factorial-helper (x accumulator)
(if (zerop x)
accumulator
(factorial-helper (- x 1) (* accumulator x)))))
(factorial-helper number 1)))
@Denommus
Denommus / azureoverlay.nix
Created March 7, 2019 20:15
This file should be in `~/.config/nixpkgs/overlays`. This will fix nixopsUnstable
self: super: rec {
nixopsUnstable = super.nixopsUnstable.overrideAttrs (oldAttrs: {
preConfigure = ''
find . -iname azure_common.py -exec sed -i 's/NetworkResourceProviderClient/NetworkManagementClient/' {} \;
find . -iname azure_vm.py -exec sed -i 's/from azure.mgmt.network import PublicIpAddress, NetworkInterface, NetworkInterfaceIpConfiguration, IpAllocationMethod, PublicIpAddressDnsSettings, ResourceId/from azure.mgmt.network.models import PublicIPAddress, NetworkInterface, NetworkInterfaceIPConfiguration, IPAllocationMethod, PublicIPAddressDnsSettings\nfrom azure.mgmt.batchai.models import ResourceId/' {} \;
find . -iname azure_availability_set.py -exec sed -i 's/from azure.mgmt.compute import AvailabilitySet/from azure.mgmt.compute.models import AvailabilitySet/' {} \;
find . -iname azure_resource_group.py -exec sed -i 's/from azure.mgmt.resource import ResourceGroup/from azure.mgmt.resource.resources.models import ResourceGroup/' {} \;
find . -iname azure_storage.py
@Denommus
Denommus / integral.hs
Last active April 22, 2022 15:24
Numeric integral implementation (Simpson method) in different languages
integral :: (Fractional a, Ord a) => (a -> a) -> Integer -> a -> a -> a
integral f p a b
| a==b = 0
| otherwise = total 0 a
where dx = (b-a)/fromInteger p
total t x | x2>b = t
| otherwise = total (t+(dx*(f x+(4*f ((x+x2)/2))+f x2)/6)) x2
where x2 = x+dx
@Denommus
Denommus / monad.ml
Last active August 26, 2020 03:53
Monad sigs and functors for OCaml
(* I'm using the new syntax sugars on 4.08, which are (let+), (and+) and ( let* ) *)
module type FUNCTOR = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val (let+): 'a t -> ('a -> 'b) -> 'b t
end
module DefaultLetPlus(M: sig
type 'a t
@Denommus
Denommus / build.rs
Created June 15, 2019 14:50
I'm so proud of this build file.
extern crate bindgen;
extern crate cmake;
extern crate filetime;
use std::env;
use std::fs;
use filetime::FileTime;
fn generate_bindings(out_dir: &str) {
let ode_dir = format!("{}/build", out_dir);
[0] % nixops deploy -d bawebsite-ec2
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/n
ixpkgs' does not exist, ignoring
error: value is null while a set was expected, at /nix/store/m0yxkvg915ws5z1yc
sblfx85nhf90p4b-nixpkgs-19.03pre161900.61c3169a0e1/nixpkgs/pkgs/top-level/defa
ult.nix:63:5
error: evaluation of the deployment specification failed
trait PrintError<E> {
fn print_err(self, message: &'static str) -> Self;
// The String type is allocated in the heap, so when a String is needed it's better to have a function that only allocates it in case it's necessary
fn print_err_with<F>(self, message_f: F) -> Self
where F: Fn(&E) -> String;
}
impl<T, E> PrintError<E> for Result<T, E> {
fn print_err(self, message: &'static str) -> Result<T, E> {
{
gitlab = { config, pkgs, ... }: {
deployment = {
targetEnv = "virtualbox";
virtualbox.memorySize = 1024;
virtualbox.vcpu = 2;
};
};
}
{
webserver = { config, pkgs, ... }: {
deployment = {
targetEnv = "virtualbox";
virtualbox.memorySize = 1024;
virtualbox.vcpu = 2;
};
};
}