Skip to content

Instantly share code, notes, and snippets.

View mrnkr's full-sized avatar
🏠
Working from home

Alvaro Nicoli mrnkr

🏠
Working from home
View GitHub Profile
@mrnkr
mrnkr / .zshrc
Created November 30, 2021 18:42
My .zshrc
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
@mrnkr
mrnkr / calculateValueWithJsonLogic.json
Created November 9, 2020 12:29
Compute value form.io - this calculation will be performed on build time and the result will be stored in the db, not the logic to compute it
{
"key": "customConditional",
"type": "hidden",
"input": false,
"clearOnHide": false,
"calculateValue": {
"==": [
{ "==": [{ "var": "component.conditional.show" }, "true"] },
{ "==": [{ "var": "data[component.conditional.when].value" }, { "var": "component.conditional.eq" }] },
]
@mrnkr
mrnkr / ExtractUserExtension.cs
Last active April 9, 2020 00:03
This is how I retrieve the user from my request without tears
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace TwoDrive.Api
{
public static class ExtractUserExtension
{
protected static string GetLoggedUserId(this ControllerBase ctrl)
@mrnkr
mrnkr / Startup.cs
Created April 8, 2020 03:05
This is how to configure JwtBearer authentication in C# to use a firebase id token
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://securetoken.google.com/firebase-project";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = "https://securetoken.google.com/firebase-project",
ValidateAudience = true,
@mrnkr
mrnkr / TokenService.cs
Created April 8, 2020 02:56
This is how I create jwt tokens in C#
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
namespace TwoDrive.Core
{
public class TokenService
@mrnkr
mrnkr / profit.c
Last active December 16, 2019 14:20
Quick coding challenge - given an array of numbers let i the current element, calculate x as the difference between i and some element after it so as to maximize x
#include<stdio.h>
int max(int a, int b) {
return a > b ? a : b;
}
int max_profit(int* values, size_t len) {
if (len == 1) return 0;
int ret = 0;
@mrnkr
mrnkr / RectangleFinder.hs
Created December 16, 2019 14:16
Quick coding challenge - find all horizontal rectangles formed given a list of points
module RectangleFinder where
import Prelude hiding ((*))
import qualified Data.Map as Map
type Point = (Int, Int)
countRects :: [Point] -> Int
countRects pts = fst $ foldl processPoints (0, Map.empty) $ filter isAbove $ pts * pts
@mrnkr
mrnkr / Program.cs
Created June 10, 2019 17:29
A simple example of reflection. Getting the first class that implements a given interface and calling one of its methods.
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using FindMe;
namespace TestProj
{
class Program
{
@mrnkr
mrnkr / phone.js
Created March 3, 2019 16:55
Uruguayan phone number validation regex for javascript
// accepts cell phone numbers like 091345876 and allows for spacing every three numbers
// accepts landline numbers like 26230945 (optional spacing 2 623 09 45)
const phone = /^((09[1-9](\s?)([0-9]{3})(\s?)([0-9]{3}))|((2|4)(\s?)([0-9]{3})(\s?)([0-9]{2})(\s?)([0-9]{2})))$/g;
@mrnkr
mrnkr / FileUpload.tsx
Created February 13, 2019 02:33
Simple React component which handles the uploading of jpeg images to my rest api
import React, { Component } from 'react';
import { connect } from 'react-redux';
import uuid from 'uuid/v4';
import { baseUrl } from '../../environment.json';
import { MyState, MyThunkDispatch } from '../../typings/state';
import { User } from '../../typings/user';
type Type =
'avatar' |
'item' |