Skip to content

Instantly share code, notes, and snippets.

View edinella's full-sized avatar
🐝
“Nothing will work unless you do.” — Maya Angelou

Ezequias Dinella edinella

🐝
“Nothing will work unless you do.” — Maya Angelou
View GitHub Profile
@edinella
edinella / ObjectId and Pydantic.py
Last active June 23, 2023 14:36
How Pydantic can handle `id` as string and `_id` as ObjectId for PyMongo
from typing import List, Optional
from bson import ObjectId
from pydantic import BaseModel, Field
class PyObjectId(ObjectId):
@classmethod
def __get_validators__(cls):
yield cls.validate
@edinella
edinella / .bash_profile
Created February 23, 2019 04:16 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
#! /bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
printf "Use BRANCH and ALIAS as arguments. Ex:\n"
printf "./deploy.sh develop tangerine\n"
exit 1
fi
GITBRANCH=$1
ALIAS=$2
@edinella
edinella / textLike.js
Created November 26, 2015 16:27
MongoDB Query similar to SQL "LIKE"
module.exports = function textLike(str) {
var escaped = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
return new RegExp(escaped, 'i');
};
// Forked from kaushikgopal/.phoenix.js
// Released under MIT license - http://opensource.org/licenses/MIT
var BROWSER;
var EDITOR;
var FINDER;
var GRID_HEIGHT;
var GRID_WIDTH;
var MARGIN_X;
var MARGIN_Y;
// request context
function Context(reqArgs, entity) {
this.req = reqArgs.req;
this.res = reqArgs.res;
this.next = reqArgs.next;
this.entity = entity;
}
Context.prototype.handleErrors = function(fn) {
var context = this;
@edinella
edinella / kill_process_on_port.sh
Last active February 7, 2024 19:48
Error: listen EADDRINUSE: address already in use
sudo kill $(sudo lsof -t -i:8080)
@edinella
edinella / snake-case to camelCase.js
Created November 7, 2013 05:35
Converte snake-case para camelCase
var snakeCaseStr = 'lorem-ipsum';
var camelCaseStr = snakeCaseStr.replace(/(\-\w)/g, function(match){return match[1].toUpperCase();});
// implementation
var Beat = require('beat');
module.exports = function(alias) {
var app = new Beat(alias);
var BeatObject = function BeatObject(callback) {
for(var key in BeatObject)
if(BeatObject.hasOwnProperty(key)) {
var keyParts = key.match(/^(.+)Factory$/);
if(keyParts === null)
app.value(key, BeatObject[key]);
@edinella
edinella / js_to_csv.js
Created October 25, 2013 12:31
JS to CSV
var dados = [
['Nome', 'Sobrenome', 'Profissão'],
['Paula', 'Tejando', 'Adivinha' ],
['Cuca', 'Beludo', 'Padeiro' ],
['Thomas', 'Turbano', 'Popeye' ]
];
var csv = dados.map(function(linha){
return linha.map(function(celula){
return '"'+(celula.replace(/\"/g, '\"').replace(/\r/g, '\\r'))+'"';