Skip to content

Instantly share code, notes, and snippets.

View dhonx's full-sized avatar
🚩
Working on Private Projects

Don Alfons Nisnoni dhonx

🚩
Working on Private Projects
View GitHub Profile
pub fn header(otext, divider string) string {
cols, _ := get_terminal_size()
mut text := otext
if text.len > 0 {
text = ' $text '
}
// clip the text if it is too long
text = if cols > text.len + 1 + 2*divider.len { text } else { text[0..cols-(1+2*divider.len)] }
// make the text align with the terminal size:
if (text.len % 2) != (cols % 2 ) {
@dhonx
dhonx / getLastInMap.js
Created January 17, 2020 15:47 — forked from tizmagik/getLastInMap.js
ES6 Last Item in Map()
// Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted:
export const getLastItemInMap = map => Array.from(map)[map.size-1]
export const getLastKeyInMap = map => Array.from(map)[map.size-1][0]
export const getLastValueInMap = map => Array.from(map)[map.size-1][1]
// Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity.
@dhonx
dhonx / relativePath.js
Created January 14, 2020 20:14 — forked from eriwen/relativePath.js
Get relative file path in JavaScript
/**
* Given a source directory and a target filename, return the relative
* file path from source to target.
* @param source {String} directory path to start from for traversal
* @param target {String} directory path and filename to seek from source
* @return Relative path (e.g. "../../style.css") as {String}
*/
function getRelativePath(source, target) {
var sep = (source.indexOf("/") !== -1) ? "/" : "\\",
targetArr = target.split(sep),
@dhonx
dhonx / gist:068314e97b644be9bbc5b2411df32753
Created January 8, 2020 01:55 — forked from kitek/gist:1579117
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@dhonx
dhonx / git-clearHistory
Created December 29, 2019 16:51 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@dhonx
dhonx / Files changed since last tag
Created December 22, 2019 07:10 — forked from arnold-almeida/Files changed since last tag
GIT: Files changed since last tag
#!/bin/bash
unset GIT_DIR
cd /path/to/project
# Get our info....
LATEST_TAG=$(git describe --tags --abbrev=0)
CURRENT_REVISION=$(git describe)
NUMBER_FILES_CHANGED=$(git diff --name-only HEAD $LATEST_TAG | wc -l)
#FILES_CHANGED=$(git diff --name-only HEAD $LATEST_TAG)
@dhonx
dhonx / store_v_function_on_array.v
Created November 17, 2019 18:17
Store function on array - V Programming Language
struct Sintf {
func fn() int
}
// Helper for calling the function
fn callf(p voidptr) int {
f := Sintf{ p }.func
return f()
}
@dhonx
dhonx / update_branch_list_from_remote.sh
Created November 8, 2019 07:08
Git: Update Branch List from Remote
# Source: https://stackoverflow.com/questions/36358265/when-does-git-refresh-the-list-of-remote-branches
# To update the local list of remote branches:
git remote update origin --prune
@dhonx
dhonx / revert_commit.sh
Created September 29, 2019 01:37
Revert Git Commit
# Checkout the desired branch
git checkout <branch>
# Undo the desired commit
git revert <commit>
# Update the remote with the undo of the code
git push origin <branch>
@dhonx
dhonx / gist:067df9f44bf0b727fac035b7c11a3936
Last active November 8, 2019 07:09 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream