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 ) {
@tejom
tejom / hello-world.cc
Created November 24, 2016 01:42
console.log v8
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <iostream>
@tizmagik
tizmagik / getLastInMap.js
Created August 13, 2016 03:22
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.
@DannyDelott
DannyDelott / getTimeLeft().js
Last active July 6, 2019 13:22
Show time left until noon using Moment.js
var getTimeLeft = function(){
var now = moment();
var deadline = now.clone().hour(12).minute(0),second(0);
if(now.isAfter(deadline) {
// disable RSVP button here
return ‘Closed’;
}else {
// enable RSVP button here
// returns “in x hours”, “in x minutes”, “in a few seconds”
return deadline.from(now);
@fomightez
fomightez / remove blank lines regex.md
Last active June 5, 2024 01:40
remove all blank lines using regular expressions
@stephenhardy
stephenhardy / git-clearHistory
Created April 26, 2013 22:14
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
@matze
matze / sorted-and-filtered-tree-view.c
Created October 22, 2012 20:33
A sorted and a filtered Gtk+ tree view
#include <gtk/gtk.h>
enum
{
COLUMN_ARTICLE = 0,
COLUMN_PRICE,
N_COLUMNS
};
typedef struct
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
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
@kitek
kitek / gist:1579117
Created January 8, 2012 17:50
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@arnold-almeida
arnold-almeida / Files changed since last tag
Created October 14, 2009 04:43
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)