Skip to content

Instantly share code, notes, and snippets.

View hectr's full-sized avatar

Hèctor M. R. hectr

  • Barcelona, Spain
View GitHub Profile
@hectr
hectr / sudoku.pl
Created December 3, 2024 21:22
Brute-force sudoku solver
% Define digits from 1 to 9
digit(1).
digit(2).
digit(3).
digit(4).
digit(5).
digit(6).
digit(7).
digit(8).
digit(9).
@hectr
hectr / PrologParser.swift
Created November 28, 2024 00:27
Prolog subset parser.
// Derived from https://github.com/photonlines/Python-Prolog-Interpreter
import Foundation
// MARK: - Primitives
/// Rules are used to define relationships between facts and other rules.They
/// allow us to make conditional statements about our world. Let's say we want to say
/// that all humans are mortal. We can do so using the rule below: mortal(X) :-
/// human(X).
@hectr
hectr / copy
Last active January 15, 2025 11:46
copy: Aggregates and formats into a markdown list the file contents from multiple directories or files
#!/usr/bin/env python3
import os
import argparse
import pyperclip
import sys
import re
def parse_arguments():
parser = argparse.ArgumentParser(
#!/usr/bin/env zsh
################################################################################
# Prepare environment
################################################################################
# Function to echo script description.
function help() {
label "" ""
label "dim" "Generates mocks for the AutoMockable protocols of the given target."
@hectr
hectr / label.sh
Created September 21, 2024 13:41
#!/usr/bin/env zsh
# Function to echo text with specified styles. Only Zsh is supported.
label() {
local -r style_string="$1"
shift # remove the first argument, leaving only the text to be styled
local text="$*"
local codes=""
local -r reset_code="\033[0m"
local code_str=""
@hectr
hectr / copilot_suggestion.py
Last active January 15, 2025 11:45
copilot_suggestion.py: GitHub Copilot LSP Integration in Python
import subprocess
import os
import time
import pathlib
import pylspclient
from pylspclient import lsp_structs
def get_uri_from_path(path: str) -> str:
@hectr
hectr / gist:55890ac2e1a24b683d02ecc1e695ea53
Created March 2, 2018 17:00 — forked from Madsy/gist:1088393
Fixedpoint versions of ln, pow, exp, sqrt and division
/*
Copyright (c) 2011, Mads A. Elvheim
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
@hectr
hectr / utf8.c
Created March 2, 2018 04:57 — forked from stanislaw/utf8.c
Some C functions to work with UTF-8 string : you can check if a string is valid UTF-8, get the length of a UTF-8 string and replace things in a UTF-8 string. All `char *` arguments must be regular, null-byte terminated, C strings. I've tried to optimize the best I could. I'd be grateful for any suggestions or improvements. Please note I have onl…
//
// utf8.c
// training
//
// Created by Conrad Kleinespel on 5/27/13.
// Copyright (c) 2013 Conrad Kleinespel. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@hectr
hectr / .gitconfig
Last active October 16, 2018 20:34
Git config file
[user]
# TODO: set name and email
#name = <name>
#email = <email>
excludesfile = ~/.gitignore_global
editor = vim
[merge]
tool = Kaleidoscope
[mergetool]
prompt = false
@hectr
hectr / random_string
Last active January 1, 2017 18:38
Returns random string of length 32.
#! /bin/bash
################################################################################
#
# Returns random string of length 32.
#
# Example:
# ./random_string
#
################################################################################