Skip to content

Instantly share code, notes, and snippets.

// sample file to run on a native machine using systemd:
// https://blog.r0b.io/post/running-node-js-as-a-systemd-service/
// deno run -Ar
import { listenAndServe } from "https://deno.land/std/http/server.ts"
const VERSION = 6
const boot = new Date().toJSON()
let counter = 0
console.log("Listening on http://localhost:8080")
@neves
neves / README.md
Last active September 2, 2020 10:39

if import as recommended in https://www.npmjs.com/package/@tsconfig/recommended it gives the follow error: (treats tsconfig.json as a directory)

esbuild index.ts
tsconfig.json:2:13: error: Cannot read file "node_modules/@tsconfig/recommended/tsconfig.json/tsconfig.json": not a directory
  "extends": "@tsconfig/recommended/tsconfig.json"
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error
// este é o único arquivo que faz import externo
// assim as dependências ficam centralizadas em um único local
// também fica explício exatamente qual função está sendo utilizada de cada módulo
export * as v4 from "https://deno.land/std/uuid/v4.ts"
export { red } from "https://deno.land/std/fmt/colors.ts"
@neves
neves / bookmarklet.js
Created May 24, 2020 23:58
bookmarklet.js
alert(123)
@neves
neves / rent.rb
Last active October 1, 2019 11:37
class RentDaysController < ApplicationController
before_action :set_rent_day, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
skip_before_action :verify_authenticity_token
# GET /rent_days
# GET /rent_days.json
def index
@rent_days = RentDay.all
end
import produce from 'immer'
const state = {
activeUserId: 123,
activeSessionIndex: 0,
sessions: {
123: [
{
products: [{ id: 456, name: 'iPhone' }]
}
@neves
neves / RangeInput.js
Created August 27, 2019 13:44
Test Medium Gist Chrome Extension
export default function RangeInput({value, onChange, ...props}) {
}
@neves
neves / gravatar_service.rb
Last active July 23, 2019 23:56
functional ruby
# frozen_string_literal: true
# original: https://github.com/gitlabhq/gitlabhq/blob/master/app/services/gravatar_service.rb
# Esse módulo pode ser chamado de 3 formas diferentes:
# GravatarService.call('j.doe@gmail.com')
# GravatarService.('j.doe@gmail.com')
# GravatarService['j.doe@gmail.com'] # eu prefiro essa última
module GravatarService
extend self
def call(email, size: nil, scale: 2, username: nil)
# frozen_string_literal: true
require 'sqlite3'
require 'active_record'
require 'ap'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :todos do |t|
@neves
neves / async-concat.js
Last active November 10, 2018 11:43
Concatenação de resultado paginado de API
/*
Tempo esperado para resolver: 30 minutos
Descrição do problema:
Temos uma função chamada listWithPagination que retorna um array de registros paginados.
A única maneira de conseguir um array com todos os registros,
é fazer requisições sequenciais para cada página, concatenando os resultados.
Descrição da solução:
Criar uma função chamada concatenateResults, que receba como parâmetro a função original