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 / 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 / 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 / .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 / 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 / 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 / scroll-fixed.js
Last active October 21, 2016 07:58
How to scroll fix an element
// The following code is all pseudo-code
let elem = ...; // get element we want to fix
let initScrollPosition = ...; // get initial position of element
// the following pseudo-code should be is in a scrolling listener
if (window.scrollYLevel > initScrollPosition) {
elem.css.position = 'fixed';
elem.css.top = 0; // 0 or other position we'd want
} else {
@nash403
nash403 / groupBy.js
Created October 10, 2016 14:23
Group array elements upon a criteria.
/*
* @param property string, number or function. This is the crieteria of the grouping function
*/
function groupBy(arr, property) {
return arr.reduce( (memo, el, i) => {
let grpProperty = (() => {
if (typeof property === 'string' || typeof property === 'number') {
return el[property];
} else if (typeof property === 'function') {
return property(el, i, arr);
@nash403
nash403 / minimal.html
Created October 5, 2016 11:44
minimal HTML code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<!-- page content -->