Skip to content

Instantly share code, notes, and snippets.

// respond variable was given before
function displayContent(attrName, lang) {
const valid_attrs = ["title", "abstract"]
const valid_langs = ["en", "nl", "fr"]
// validate attrName and lang before accessing property
if (valid_attrs.includes(attrName) && valid_langs.includes(lang)) return respond.data[attrName][lang]
return null
}
@shcyiza
shcyiza / auth2_services.js
Last active May 26, 2022 08:36
showing off how to dynamically invoke function in JS
const OAUTH2_OPTIONS = {
facebookLogin() {
// do the oath2 procedure for FB
},
googleLogin() {
// do the oath2 procedure for google
},
instagramLogin() {
// do the oath2 procedure for instagram
}
{
"data": {
"GetTodosAsAssignee": [
{
"id": 7,
"report_id": 64,
"text": "do the dishes",
"status": "awaiting",
"assignee": [
@shcyiza
shcyiza / car_brands.json
Created September 2, 2019 21:30
list of car brands name and logo in JSON format
[
{
"logo": "https://www.car-logos.org/wp-content/uploads/2011/09/abarth1.png",
"name": "Abarth"
},
{
"logo": "https://www.car-logos.org/wp-content/uploads/2011/09/ac-cars.png",
"name": "AC"
},
{
@shcyiza
shcyiza / ssccee_where_statement_with_included_model.js
Last active November 5, 2019 13:49
SSCCE paginate where statement with included model issue
'use strict';
module.exports = async function(createSequelizeInstance, log) {
const { Sequelize, Op, Model, DataTypes } = require('sequelize');
const sequelize = createSequelizeInstance({ benchmark: true });
await sequelize.authenticate();
const Report = sequelize.define('Report', {
name: DataTypes.STRING,
@shcyiza
shcyiza / Startup.cs
Last active January 23, 2020 18:16
access env var in dotnet core
public Startup(IConfiguration configuration)
{
Configuration = configuration;
StaticConfig = configuration;
}
public static IConfiguration Env { get; private set; }
// to use simply call the static member from anywher in the app
// Startup.Env["Jwt:issuer"]
{
"AEAJM": {
"name": "Ajman",
"city": "Ajman",
"country": "United Arab Emirates",
"alias": [],
"regions": [],
"coordinates": [
55.5136433,
25.4052165
@shcyiza
shcyiza / error_response.json
Last active February 1, 2020 12:07
error response body exemple
{
"error": [
{"message": "Incorrect"}
],
"status": 400,
}
@shcyiza
shcyiza / responder_middleware.js
Last active February 17, 2020 09:57
express api json resposder
'use strict'
/*
* API middleware
*
* Adds shortcut methods for JSON API responses (inspired by KeystoneJS) :
*
* `res.apiResponse(data)`
* `res.apiError(key, err, msg, code)`
* `res.apiNotFound(err, msg)`
@shcyiza
shcyiza / reactSocet.js
Last active February 26, 2020 19:28
socet listen to message on react
socket.on('Room_45IDFDQSDFA', data => {
this.setState('messages', this.messages.push(data.message))
});