Skip to content

Instantly share code, notes, and snippets.

# https://stackoverflow.com/questions/15769948/round-a-python-list-of-numbers-and-maintain-the-sum
from decimal import Decimal, ROUND_HALF_UP
def round_amounts(amounts, original_amount, decimal_places):
amounts = [Decimal(str(amount)) for amount in amounts]
places = Decimal(10) ** -decimal_places
rounded_list = (
[amount.quantize(places, ROUND_HALF_UP) for amount in amounts])
@snake575
snake575 / GuidUtility.cs
Last active January 12, 2021 19:06
Deterministic GUID utility class for C# according to RFC 4122 (from: http://faithlife.codes/blog/2011/04/generating_a_deterministic_guid)
using System;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// Helper methods for working with <see cref="Guid"/>.
/// </summary>
public static class GuidUtility
{
/// <summary>
Public Function RUTDV(rut)
rut = Replace("0000" & rut, ".", "", 1)
If InStr(1, rut, "-") > 0 Then rut = Left(rut, InStr(1, rut, "-") - 1)
rut = Right(rut, 8)
suma = 0
For i = 1 To 8
suma = suma + Val(Mid(rut, i, 1)) * Val(Mid("32765432", i, 1))
Next i
dv = 11 - (suma Mod 11)
If dv = 10 Then dv = "k"
@snake575
snake575 / firebase.scheme.js
Last active March 23, 2020 13:18
Nuxt auth with Firebase (provider redirect)
// Firebase auth scheme
// https://auth.nuxtjs.org/guide/scheme.html#schemes
import firebase from 'firebase/app'
import 'firebase/auth'
const DEFAULTS = {
appName: undefined,
token_type: 'Bearer',
userinfo_endpoint: `https://identitytoolkit.googleapis.com/v1/accounts:lookup`,