Skip to content

Instantly share code, notes, and snippets.

Avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
lionello / stashd.d
Last active Aug 7, 2022
Tool to find GIT stashes containing changes to specified file(s)
View stashd.d
#!/usr/bin/env rdmd
// Get rdmd from https://dlang.org/download.html (or brew, nix, apt, yum)
// Copyright Lionello Lunesu. Placed in the public Domain.
// https://gist.github.com/lionello/84cad70f835131198fee4ab7e7592fce
import std.stdio : writeln;
int main(string[] args) {
import std.process : pipeProcess, wait, Redirect;
@lionello
lionello / base64url
Last active Aug 6, 2022
base64url: wrapper script for base64
View base64url
#!/usr/bin/env bash
# Source: https://gist.github.com/lionello/6bb597fc600932c6c737aab3b402147c
ignore=0
decode=0
dashdash=0
args=()
files=()
while [ $# -gt 0 ]; do
@lionello
lionello / writevt.c
Last active Aug 1, 2022
Forked writevt from console-tools
View writevt.c
/*
* Mostly ripped off of console-tools' writevt.c
*/
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
@lionello
lionello / Versioning.sh
Created Jun 13, 2022 — forked from bgreenlee/Versioning.sh
Automatic project versioning for Xcode using git commits & tags #xcode #git
View Versioning.sh
#!/bin/sh
# Versioning.sh
#
# https://gist.github.com/791352 by Marc Hedlund
#
# Found at http://kswizz.com/post/2686511526/git-xcode-versioning and slightly
# modified.
# To install:
@lionello
lionello / cas128.c
Last active Apr 7, 2022
__sync_val_compare_and_swap for __uint128_t GCC built-in
View cas128.c
/*
__sync_val_compare_and_swap that works with __uint128_t, by Lionello Lunesu.
Placed in the public domain
*/
#undef NDEBUG
#include <assert.h>
inline __uint128_t InterlockedCompareExchange128( volatile __uint128_t * src, __uint128_t cmp, __uint128_t with )
{
__asm__ __volatile__
@lionello
lionello / ModExp.sol
Last active Mar 17, 2022
Solidity wrapper for Ethereum Byzantium's BigInt `modexp` built-in contract 0x5
View ModExp.sol
pragma solidity ^0.4.17;
contract ModExp {
// Wrapper for built-in bigint_modexp (contract 0x5) as described here https://github.com/ethereum/EIPs/pull/198
function modexp(bytes memory _base, bytes memory _exp, bytes memory _mod) public view returns(bytes memory ret) {
uint256 bl = _base.length;
uint256 el = _exp.length;
uint256 ml = _mod.length;
@lionello
lionello / ECMath.sol
Last active Mar 16, 2022
ECDSA verification and recovery for curve secp256r1
View ECMath.sol
/*
MIT License
Copyright (c) 2018 Lionello Lunesu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@lionello
lionello / translatekeycodes.swift
Created Jan 18, 2022 — forked from ArthurYidi/translatekeycodes.swift
virtual key codes to unicode characters
View translatekeycodes.swift
private static func keyCodeToString(keyCode: CGKeyCode, eventModifiers: Int) -> String? {
let curKeyboard = TISCopyCurrentKeyboardInputSource().takeRetainedValue()
let rawLayoutData = TISGetInputSourceProperty(curKeyboard, kTISPropertyUnicodeKeyLayoutData)
let layoutData = unsafeBitCast(rawLayoutData, to: CFData.self)
let keyboardLayoutPtr = unsafeBitCast(CFDataGetBytePtr(layoutData), to: UnsafePointer<UCKeyboardLayout>.self)
var deadKeyState: UInt32 = 0
var actualStringLength = 0
var unicodeString: [UniChar] = [0, 0, 0, 0]
View DefaultKeyBinding.dict
{
/* put this file in ~/Library/KeyBindings/ */
/* Home */
"\UF729" = "moveToBeginningOfLine:";
"^\UF729" = "moveToBeginningOfDocument:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"^$\UF729" = "moveToBeginningOfDocumentAndModifySelection:";
/* End */
View .emacs
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
(setq package-enable-at-startup nil)
(package-initialize)
(custom-set-variables