Skip to content

Instantly share code, notes, and snippets.

@MauricioMoraes
MauricioMoraes / print_element.html
Last active February 5, 2020 18:13
Print the contents of a div with a given stylesheet
<html>
<body>
<div id='print-wrapper'>
<h1>CONTENT TO PRINT</h1>
<p>CONTENT TO PRINT</p>
<p>CONTENT TO PRINT</p>
<p>CONTENT TO PRINT</p>
<p>CONTENT TO PRINT</p>
<p>CONTENT TO PRINT</p>
@MauricioMoraes
MauricioMoraes / print_element.html
Created February 5, 2020 18:04
Print the contents of a div with a given stylesheet
<div id='print-wrapper'>
CONTENT TO PRINT
</div>
<button id="print">PRINT</button>
@MauricioMoraes
MauricioMoraes / access_postgresql_with_docker.md
Last active May 2, 2024 10:21
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@MauricioMoraes
MauricioMoraes / list-files-in-folder.js
Created June 2, 2016 11:56 — forked from hubgit/list-files-in-folder.js
List all files in a folder (Google Apps Script)
function listFilesInFolder() {
var folder = DocsList.getFolder("Maudesley Debates");
var contents = folder.getFiles();
var file;
var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
@MauricioMoraes
MauricioMoraes / delete_all_shapes_from_xls.vba
Created March 30, 2016 13:24
Deletes all pictures and shapes from excel spreadsheet (does it for all sheets inside the document)
Option Explicit
Sub delete_all_shapes()
Dim shape As Shape
Dim worksheet As Worksheet
Dim response As Integer
response = MsgBox("This action will delete all pictures and shapes from your spreadsheet. Do you want to continue?", vbYesNo, "Delete all shapes from spreadsheet")
If response = vbYes Then
For Each worksheet In ThisWorkbook.Worksheets
@MauricioMoraes
MauricioMoraes / brazilian_phone_mask_with_area_code.js
Last active May 16, 2022 04:10
Mask for 8 or 9 digit phones in brazilian format with area code (ddd) - Using Jquery.inputmask plugin
// Using jquery.inputmask: https://github.com/RobinHerbots/jquery.inputmask
// For 8 digit phone fields, the mask is like this: (99) 9999-9999
// For 9 digit phone fields the mask is like this: (99) 99999-9999
function setupPhoneMaskOnField(selector){
var inputElement = $(selector)
setCorrectPhoneMask(inputElement);
inputElement.on('input, keyup', function(){
setCorrectPhoneMask(inputElement);
});
@MauricioMoraes
MauricioMoraes / column_numbers_from_names.gs
Last active October 22, 2015 12:47
Get column numbers from column names - Google apps scripts for spreadsheets
// Pass the column headers range and names, and it will return an object with the relation between column names and column numbers
function getColumnNumbersForNames(sheetName, columnHeadersRangeA1Notation, columnNames){
var thisSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = thisSpreadsheet.getSheetByName(sheetName);
var columnHeadersRange = sheet.getRange(columnHeadersRangeA1Notation);
var columnNamesOnSheet = flatten(columnHeadersRange.getValues());
var columnNumbersForNames = {};
for(var count = 0; count < columnNames.length; count++){
var columnName = columnNames[count]
@MauricioMoraes
MauricioMoraes / one_level_flatten.js
Created October 22, 2015 12:00
Javascript Flatten (for one level nested arrays) - Useful for google apps scripts on spreadsheets
// Takes and array of arrays matrix and return an array of elements.
function flatten(arrayOfArrays){
return [].concat.apply([], arrayOfArrays);
}
@MauricioMoraes
MauricioMoraes / jquery_datatable_checkboxes_with_pagination.js
Last active August 29, 2015 14:26
Jquery DataTables - Workaround to have a selectable list of options with dataTables and Pagination. When the form is submitted, the script inserts hidden inputs with the values of the checkboxes that are not visible, due to pagination.
function setupDatatableCheckboxesWithPagination(tableSelector, attributeName) {
var dataTableObject = $(tableSelector).dataTable();
form = $(tableSelector).closest("form");
$(form).submit(function(){
insertHiddenInputsWithCheckboxesValues(tableSelector, attributeName);
dataTableObject.fnFilter('');
});
};
@MauricioMoraes
MauricioMoraes / gist:a8f4b4bd89b647b749f5
Created July 27, 2015 16:57
Google Apps Script for Spreadsheets - Find the relative row number within a range that has a a cell with given target value - Range in A1 Notation starting
function findRowNumberForCellWithValue(targetValue, rangeA1Notation, sheet) {
var range = sheet.getRange(rangeA1Notation);
var values = range.getValues()
for (var i = 0; i < values.length; i++) {
if (values[i][0] == targetValue) {
return i+1;
}
}
}