Skip to content

Instantly share code, notes, and snippets.

View nash403's full-sized avatar
🦄
want a cookie ?

Honoré Nintunze nash403

🦄
want a cookie ?
View GitHub Profile
@nash403
nash403 / query.js
Created December 7, 2016 15:01
A good compromise between querySelectorAll and getElementsBy[...] functions !
function query(selector, context) {
context = context || document;
// Redirect simple selectors to the more performant function
if (/^(#?[\w-]+|\.[\w-.]+)$/.test(selector)) {
switch (selector.charAt(0)) {
case '#':
// Handle ID-based selectors
return [context.getElementById(selector.substr(1))];
case '.':
// Handle class-based selectors
@nash403
nash403 / get-file-extension.js
Created December 20, 2016 08:53
An efficient way to get a file extension from the file's name
// Does not handle hidden files like .htaccess the way you would want though ;)
getFileExtension (filename) {
let res = filename.substr(filename.lastIndexOf('.')+1);
return res === filename ? '' : res;
}
@nash403
nash403 / .zsh_aliases
Last active February 28, 2017 09:12
My alias for zsh
# Advanced Aliases.
alias c='clear'
# ls, the common ones I use a lot shortened for rapid fire usage
alias l='ls -lFh' #size,show type,human readable
alias la='ls -lAFh' #long list,show almost all,show type,human readable
alias lr='ls -tRFh' #sorted by date,recursive,show type,human readable
alias lt='ls -ltFh' #long list,sorted by date,show type,human readable
alias ldot='ls -ld .*'
@nash403
nash403 / preload-image.js
Created March 22, 2017 14:18
Preload images in JS
let img = new Image();
img.onload = () => {
console.log('youpiiii img preloaded !')
};
img.src = 'some_url';
@nash403
nash403 / pager.ts
Last active March 23, 2017 13:35
Simple Pager structure in TypeScript
import { modulo } from "./utils";
export class Pager {
next:number = 0;
previous:number = 0;
constructor(public current:number = 0, public length:number = 0, noModulo:boolean = false) {
this.setNeighbours(noModulo);
}
@nash403
nash403 / change_user_premission.md
Last active April 12, 2017 08:06
Change user/Group permission on Unix
@nash403
nash403 / perfect-modulo.js
Created April 12, 2017 08:08
Modulo that always returns a value always between 0 and `size - 1`
/**
* Returns a value always between 0 and size - 1.
* @param a current index
* @param b size
*/
export function modulo(a, b) { return (+a % (b = +b) + b) % b; };
@nash403
nash403 / image_broken_replacement.scss
Last active April 12, 2017 08:10
hide image broken icon and replace it with alt content
img[alt] {
position: relative;
&:after {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* Add bg color and the text of the alt attribute in place of the broken image */

To completely uninstall node + npm is to do the following:

  • go to /usr/local/lib and delete any node and `node_modules
  • go to /usr/local/include and delete any node and node_modules directory
  • if you installed with brew install node, then run brew uninstall node in your terminal
  • check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  • go to /usr/local/bin and delete any node executable
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
@nash403
nash403 / rewrite-git-author.sh
Created May 18, 2017 08:08
Changing the Git history to change the author of commits. Copy paste, replace OLD_EMAIL, CORRECT_NAME & CORRECT_EMAIL and press ENTER.
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"