Skip to content

Instantly share code, notes, and snippets.

View damienbry's full-sized avatar

Damien Bry damienbry

View GitHub Profile
@damienbry
damienbry / public.login.sql
Created July 5, 2017 11:12
Hack to use env vars within your plpgsql functions #postgrest #psql
-- The architecture:
-- a hidden schema that contains sensitive info
-- a public schema exposed by postgrest (https://github.com/begriffs/postgrest)
-- the problem: you can't populate env vars with psql within plpgsql functions
-- I wanted to have my jwt_secret not in clear in the code
-- so that I can switch environments and not expose this token on github
-- step 1: create a enum type in the hidden schema containing only your variable
create type hidden.jwt_secret as enum (:jwt_secret);
firstname name email pseudo avatar_url password external_id role chat_enabled website max_chat location conversation_number
import1 import1 import1@gmail.com tarass https://yt3.ggpht.com/-z5BZ8hRtQ8U/AAAAAAAAAAI/AAAAAAAAAAA/PQpARaPvj-Q/s88-c-k-no-mo-rj-c0xffffff/photo.jpg tamertamer 1 admin 1 1 4 World 0
app.get('/seed', function (req, res) {
if (req.headers['x-mentorleo-token'] != 'MENTORLEO') {
res.send('NOK');
} else {
// DO STUFF
res.send('OK');
}
});
const config = {
dbURI: process.env.MONGODB_ADDON_URI ? process.env.MONGODB_ADDON_URI : 'mongodb://localhost:27017'
};
const assert = require('assert'); // Lib already available with Node.js, no need to install anything with npm
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const config = {
dbURI: 'mongodb://localhost:27017/test'
};
const app = express();
fs.readFileAsync("file.json").then(JSON.parse).then(function (val) {
console.log(val.success);
})
.catch(SyntaxError, function (e) {
console.error("invalid json in file");
})
.catch(function (e) {
console.error("unable to read file");
});
fs.readFile("file.json", function (err, val) {
if (err) {
console.error("unable to read file");
}
else {
try {
val = JSON.parse(val);
console.log(val.success);
}
catch (e) {
var express = require('express');
var app = express();
app.get('/hello', function (req, res) {
res.send('Hello World!');
});
app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
var mentor = '@damien';
console.log('My Mentor for this mentorleo.co project is ' + mentor);
module.exports = React.createClass({
// The state is an object with keys that represents the text of the labels
// And value is the activation / disabled
//
// From var obj = {mentor: 'Léo', week2: 'Day5'}
// We can get the array of the keys by using Object.keys(obj)
// This should give ['mentor', 'week2']
getInitialState() {
return {
skills: {