Skip to content

Instantly share code, notes, and snippets.

View guaiamum's full-sized avatar
🌞

Cainã Brazil guaiamum

🌞
View GitHub Profile
@guaiamum
guaiamum / JavascriptDateSnippets.js
Created October 27, 2017 13:33
Javascript Date Snippets
/* FIRST AND LAST DAY OF WEEK */
var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay(); // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6
var firstday = new Date(curr.setDate(first)).toUTCString();
var lastday = new Date(curr.setDate(last)).toUTCString();
/* TOMORROW */
var tomorrow = new Date();
@guaiamum
guaiamum / localArrayWithdataTables.js
Last active November 21, 2017 17:32
Kind of universal script to store entity in local array, edit via ajax and display in DataTables.
var table;
var perguntas = [];
var codigoPerg = 0;
var acoes = '<i class="fa fa-arrow-up fa-lg praCima"></i> <i class="fa fa-arrow-down fa-lg praBaixo"></i> <i class="fa fa-pencil fa-lg editar" title="' + Resources.EDITAR + '"></i> <i class="fa fa-trash-o fa-lg remover" style="color: #ff0000" title="' + Resources.REMOVER +'"></i>';
function updateTablePerguntas() {
table.clear();
perguntas.sort(function (a, b) { return a.Ordem - b.Ordem; });
table.rows.add(perguntas).draw();
}
@guaiamum
guaiamum / replaceAll.js
Created December 5, 2017 17:33
Replace all occurrences on string, using regular expression
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
var str = "oi, tchau, adios, bye, etc";
str.toString().replaceAll(',','\n');
@guaiamum
guaiamum / centered div
Created December 20, 2017 16:38
DIV tag centered in all screens
<div class="col-lg-offset-3 col-md-offset-3 col-sm-offset-3 col-md-10">
</div>
@guaiamum
guaiamum / sexyRadioButtons.html
Last active December 21, 2017 12:03
radio button like behavior with btn-group
<style>
#radioBtn .notActive {
color: #555;
}
#radioBtn .active {
z-index: 0;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
@guaiamum
guaiamum / PromiseTimeout.js
Created January 6, 2018 20:10
No caso a seguir, criamos uma função timeout que apenas retorna um reject após tanto tempo e iniciamos uma corrida entre uma Promise de busca de dados do usuário e a Promise de timeout com dois segundos. Ou seja, se a Promise demorar mais que dois segundos, o retorno no .catch será: { timeout: true }, agora se demorar menos que isso, os dados do…
const timeout = ms => new Promise((resolve, reject) =>
setTimeout(reject, ms, { timeout: true });
);
Promise.race([api.get('/users/diego3g'), timeout(2000)])
.then(resp => console.log(resp))
.catch(err => console.log(err));
@guaiamum
guaiamum / .hyper.js
Last active October 31, 2019 10:53
My public hyper terminal settings, managed by hyper-sync-settings plugin
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// Choose either "stable" for receiving highly polished,
// or "canary" for less polished but more frequent updates
updateChannel: 'stable',
@guaiamum
guaiamum / piscaCursor.js
Last active October 24, 2018 09:28
makes cursor blink
let interval;
const blink = () => {
interval = setInterval(() => $('.cursor').toggle(), 600);
};
const stopBlinking = () => {
clearInterval(interval);
}
@guaiamum
guaiamum / getMonday.js
Created May 21, 2018 14:36
gets the monday of the given week
function getMonday(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
@guaiamum
guaiamum / generate_properties.js
Created May 28, 2018 11:05
transforms multiline property listing string into class members in c#
/**
* @param {string} str : multiline string
* @return {string} result
*/
function genProps(str){
let arr = str.split('\n');
let ini = 'public string ';
let fim = ' {get;set;}\n';
return ini+ arr.join(fim + ini) + fim;
}