Skip to content

Instantly share code, notes, and snippets.

View pnmcosta's full-sized avatar
🥷
coding remotely

Pedro Maia Costa pnmcosta

🥷
coding remotely
View GitHub Profile
@pnmcosta
pnmcosta / brunch.commonjs.module.options.js
Last active April 3, 2017 18:50
Example CommonJS Module Wrapped by Brunch with options, private and public methods and properties
/**
* Example CommonJS Module Wrapped by Brunch with options, private and public methods
* Usage with defaults: require("brunch.commonjs.options.module")()
* Usage with options: require("brunch.commonjs.options.module")({myOptionName:false})
*/
"use strict";
// require's and constants
const $ = require("jquery");
@pnmcosta
pnmcosta / totaljs-promise-schema.js
Last active September 30, 2017 15:06
Total.js - Using Promise to get schema objects
NEWSCHEMA('Form').make(function (schema) {
schema.define('contact', 'FormContact', true);
schema.define('deal', 'FormDeal', true);
schema.addWorkflow('submit', function (error, model, options, callback, controller) {
Promise.all([getDealById(options.deal_id), getContactById(options.contact_id)])
.then(function (values) {
let valid = (values[0] && value[1]); // 0 = getDealById, 1 = getContactById
if (!valid) {
error.push('deal', 'not found.');
@pnmcosta
pnmcosta / bootstrap-datepicker-single-inline-date-range.js
Last active February 9, 2023 12:33
bootstrap-datepicker single inline date range selection
/* *************** HTML *****************
* <div class="form-group search-calendar">
* <h3>Data</h3>
* <div class="bs-datepicker">
* <div class="range-start"></div>
* <div class="range-end"></div>
* </div>
* <div class="row no-gutter">
* <div class="col-md-6">
* <input type="text" name="range-end" value="" placeholder="de" class="form-control range-input" />
@pnmcosta
pnmcosta / all-sundays.js
Created February 7, 2018 11:13
Get all sundays from current month till years end (Node.js)
var template = `Dia: {0}
Hora inicio: 08h00
Briefing: 08h30
Fim: 12h30
Duração: 04h00m
\r\n`;
var monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
];
@pnmcosta
pnmcosta / vsts-fork-commands.sh
Last active July 4, 2022 05:31
Git commands to fork (and rebase) from GitHub to VSTS
# START Create Fork
# Author: Pedro Maia Costa <hello@pmcdigital.pt>
# Note: Please see Gist first comment, replace <var-name> below with your values before running.
# fork branch into vsts
cd your-project
git init .
# the target <your-repo> as origin
git remote add origin https://<your-vsts>.visualstudio.com/<your-repo-url>
@pnmcosta
pnmcosta / git-diff-archive.bat
Created June 5, 2018 18:15
Git commands to create archives of diff's
# START Create Archives
# Author: Pedro Maia Costa <hello@pmcdigital.pt>
# Note: Please see Gist first comment, replace $var-name below with your values before running.
# Create an archive of the entire current branch
git archive -o ..\deploys\full.zip HEAD
# Create a diff of the files that are different between commits
git diff --no-commit-id --name-only --diff-filter=ACMRT $commitid > ../deploys/diff_$commitid.txt
@pnmcosta
pnmcosta / work.html
Created August 6, 2018 13:39
Total.js CMS admin component
// Add this file to /components/ directory
<script total>
// groups this component with admin
exports.group = 'admin';
exports.install = function() {
// include custom routes here
};
</script>
@pnmcosta
pnmcosta / ContentNoticesMasonry-template.html
Last active August 11, 2018 10:19
Total.js CMS widgets template suggestion
<!-- This is a suggestion based on https://github.com/totaljs/widgets/blob/master/ContentNoticesMasonry/widget.html -->
<style>
.wc140 { column-width: 280px; column-gap: 20px; width: 100%; margin: 30px auto; }
.wc140 figure { width: 100%; background: white; border: 1px solid #E0E0E0; margin: 0 2px 20px; padding: 15px; display: inline-block; column-break-inside: avoid; border-radius: 4px; line-height: 18px; }
.wc140 .date { font-size: 11px; color: #A0A0A0; margin-bottom: 10px; }
.wc140 .date .fa { margin-right: 5px; }
.wc140 figure img { border-radius: 3px; }
.wc140 figure code { background-color: #F0F0F0; padding: 1px 3px; border-radius: 3px; font-size: 12px; }
.wc140 figure blockquote { background-color: #F0F0F0; padding: 10px; margin: 0 0 15px; border-radius: 4px; }
.wc140 figure p { margin-top: 0; margin-bottom: 15px; }
@pnmcosta
pnmcosta / totaljs-cms-deep-clean.js
Created November 1, 2018 12:24
Total.js Scripts
require('total.js');
var clean = function(name) {
return function(next) {
TABLE(name + 'data').remove().like('id', '_').callback(function() {
TABLE(name + 'data').clean();
NOSQL(name).clean();
next();
});
};
};
@pnmcosta
pnmcosta / components-properties.html
Last active November 13, 2018 10:52
Total.js CMS Admin Component
<script total>
// register component in admin group
exports.group = 'admin';
exports.install = function() {
// MODEL: /schemas/properties.js
ROUTE('GET #admin/api/properties/ *Property --> @query', ['&admin', 'id:properties']);
ROUTE('GET #admin/api/properties/{id}/ *Property --> @read', ['&admin', 'id:properties']);
};
exports.uninstall = function() {