This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 }') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"code2": "AF", | |
"code3": "AFG", | |
"name": "Afghanistan", | |
"capital": "Kabul", | |
"region": "Asia", | |
"subregion": "Southern Asia", | |
"states": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker exec -it container-name redis-cli FLUSHALL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
NewerOlder