Skip to content

Instantly share code, notes, and snippets.

View iolufemi's full-sized avatar

Olanipekun Femi iolufemi

View GitHub Profile
@sxiii
sxiii / remove.sh
Created October 5, 2020 05:35
Docker Swarm - Remove all Down nodes automatically
#!/bin/bash
# Requirements: linux, docker, grep, awk
# This script removes all "Down" (off) nodes from Docker Swarm
# Useful to clean stuff from time to time, if you have auto-joining nodes for example
sudo docker node rm $(sudo docker node ls | grep Down | awk -F" " '{ print $1 }')
@olanipekunife
olanipekunife / countries+states
Created August 24, 2020 09:03
list of countries with states
[
{
"code2": "AF",
"code3": "AFG",
"name": "Afghanistan",
"capital": "Kabul",
"region": "Asia",
"subregion": "Southern Asia",
"states": [
{
@olanipekunife
olanipekunife / paginations.jsx
Last active August 19, 2019 17:02
react component that can be used with Express-REST-API-Generator
import React from 'react';
const Paginations = React.memo(({ pages, lastpage, page, prev, next, pageClick }) => {
let paginations = [], showNext = page + 3, showLast = pages - 3, lastpaginations = []
for (let i = 1; i <= pages; i++) {
//show last 3
if (i >= page - 3) {
if (i < showNext) {
paginations.push(<li key={i} className={`page-item ${page === i && 'active'}`}><button onClick={() => page !== i && pageClick(i)} className="link-button page-link">{i}</button></li>)
} else if (i > showLast) {
@dimasch
dimasch / redis-clear
Last active April 13, 2024 12:39
Clear a redis cache in Docker
docker exec -it container-name redis-cli FLUSHALL
### I assume you run the commands as root
gradle_version=2.6
wget -c http://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
unzip gradle-${gradle_version}-all.zip -d /opt
ln -s /opt/gradle-${gradle_version} /opt/gradle
printf "export GRADLE_HOME=/opt/gradle\nexport PATH=\$PATH:\$GRADLE_HOME/bin\n" > /etc/profile.d/gradle.sh
source /etc/profile.d/gradle.sh
# check installation
gradle -v
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active April 13, 2024 16:19
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@justmoon
justmoon / custom-error.js
Last active April 22, 2024 17:19 — forked from subfuzion/error.md
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@jblashill
jblashill / promise.spread.js
Last active May 5, 2023 08:43
An extension to the Promise prototype to "spread" resolved data from Promise.all() to multiple function parameters
var Promise = require('es6-promise').Promise;
// idea borrowed from Q.spread
Promise.prototype.spread = function(fn) {
return this.then(function() {
if (!arguments || arguments.length === 0) {
return fn.apply();
}
return fn.apply(null, arguments[0]);
});
@kerimdzhanov
kerimdzhanov / random.js
Last active April 20, 2024 03:21
JavaScript: get a random number from a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@enreeco
enreeco / ExpressJS rawBody
Last active August 7, 2016 17:37
NodeJS ExpressJS Getting Raw Body on request object
app.configure(function() {
//. . .
app.use(express.bodyParser());
app.use(function(req, res, next) {
var data = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {