var token = jwt.sign({email_id:'123@gmail.com'}, "Stack", {
expiresIn: "10h" // it will be expired after 10 hours
//expiresIn: "20d" // it will be expired after 20 days
//expiresIn: 120 // it will be expired after 120ms
});
Category: with
how to set random dice image with js
function mathRandomDice() {
document.getElementById("dice").innerHTML = Math.floor(Math.random() * 6) + 1;
}
var x = mathRandomDice;
if (x = 1) {
d.innerHTML = '<img src=https://image.ibb.co/cQKOhc/dice1.png>';
}
how to set a status with discord.js
//have your regular bot status code
type: "streaming", url: "https://www.twitch.tv/name"
client.user.setActivity("INSERT TEXT HERE");
how to set background automatically with my screen height
html {
background: url(image.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top center;
background-size: contain;
}
how to set JSON data bootstrap treeview with java
var withText = jsondata.map(function(i) {
i['text'] = i['bibliography_text'];
return i;
});
var nestedData = d3.nest()
.key(function(d) { return d.country; })
.key(function(d) { return d.city; })
.entries(withText);
how to send dm to every member in discord with discord.js
if(checkCommandSusan(message, "notify")) {
message.guild.members.forEach(m => {
if(m.roles.includes(r => r.name === "role name") return m.send("message")
})
})
}
How to send JSON Web Token (JWT Token) as header with Postman and golang
func ProtectedEndpoint(w http.ResponseWriter, req *http.Request) {
params := req.URL.Query()
token, _ := jwt.Parse(params["token"][0], func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("There was an error")
}
return []byte("secret"), nil
})
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
var user User
mapstructure.Decode(claims, &user)
json.NewEncoder(w).Encode(user)
} else {
json.NewEncoder(w).Encode(Exception{Message: "Invalid authorization token"})
}
}
func CreateTokenEndpoint(w http.ResponseWriter, req *http.Request) {
var user User
_ = json.NewDecoder(req.Body).Decode(&user)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"username": user.Username,
})
tokenString, error := token.SignedString([]byte("secret"))
if error != nil {
fmt.Println(error)
}
json.NewEncoder(w).Encode(JwtToken{Token: tokenString})
}
how to run node js with proxy
$ npm config delete http-proxy
$ npm config delete https-proxy
$ npm config set proxy http://localhost:3128
$ npm config set https-proxy http://localhost:3128
How to scan a folder for documents with javascript
var dir = "/videos";
var fileextension = ".mp4";
$.ajax({
//This will retrieve the contents of the folder if the folder is configured as 'browsable'
url: dir,
success: function (data) {
// List all mp4 file names in the page
$(data).find("a:contains(" + fileextension + ")").each(function () {
var filename = this.href.replace(window.location.host, "").replace("http:///", "");
$("body").append($("<img src=" + dir + filename + "></img>"));
});
}
});
how to right text with js
document.write("text");