Skip to content

Instantly share code, notes, and snippets.

<?php
$file = 'myfile.php';
$last_modified_time = filemtime($file);
$etag = md5_file($file);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
@Igor-Lopes
Igor-Lopes / mongoose-timestamps.js
Created February 2, 2018 16:34
Add timestamps and expiration to mongoose schema
var schema = mongoose.Schema({
email: {
type: String,
required: true,
lowercase: true,
index: {
unique: true
}
},
expireAt: {
@Igor-Lopes
Igor-Lopes / bovespa.py
Created June 11, 2018 17:30 — forked from turicas/bovespa.py
Get stock prices from BMF Bovespa API
# coding: utf-8
# Copyright 2015 Álvaro Justen <https://github.com/turicas/rows/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@Igor-Lopes
Igor-Lopes / gitlabci-nyc-coverage.md
Created June 13, 2018 12:58
Regex for nyc code coverage in Gitlab CI

All files\s*\|\s*([0-9.]+)

@Igor-Lopes
Igor-Lopes / sequelize-transaction.js
Created July 8, 2018 19:40
Sequelize Transaction Example
let transaction
try {
transaction = await Sequelize.transaction()
let employee = await Employee.create({
name: req.body.name,
employeeId: req.body.employeeId,
birthday: req.body.birthdate
}, transaction)
@Igor-Lopes
Igor-Lopes / google-server-side-access-example.js
Last active September 6, 2018 17:18
Enable Google API Offline Server Side access with server auth code provided by mobile app (https://developers.google.com/identity/sign-in/android/offline-access)
const { google } = require('googleapis')
module.exports = app => {
const controller = {}
controller.auth = async (req, res, next) => {
try {
const oauth2Client = new google.auth.OAuth2(
'YOUR_CLIENT_ID',
@Igor-Lopes
Igor-Lopes / bovespa_intraday.py
Created October 31, 2018 23:16 — forked from maurobaraldi/bovespa_intraday.py
Cotações da Bovespa Intraday
#!/usr/bin/env python
from datetime import datetime
from json import loads
from time import gmtime, mktime, strptime
# LevelDict é um wrapper usando dicionário para LevelDB
# https://github.com/maurobaraldi/leveldict
from leveldict import LevelJsonDict
from requests import get
@Igor-Lopes
Igor-Lopes / traccar-commands.md
Created November 1, 2018 23:09
traccar service commands

Start

$sudo /etc/init.d/traccar start

Stop

$sudo /etc/init.d/traccar stop

@Igor-Lopes
Igor-Lopes / API.md
Created December 12, 2018 17:59 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@Igor-Lopes
Igor-Lopes / better-nodejs-require-paths.md
Created April 12, 2019 19:18 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions