Skip to content

Instantly share code, notes, and snippets.

FROM alpine:3.16
USER root
ENV INITSYSTEM on
ENV UDEV=1
ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
ENV BUNDLER_VERSION=2.4.12
ENV NODE_VERSION=14.20.0
ENV YARN_VERSION=1.22.17
@caio-nas
caio-nas / query_comparison.rb
Last active April 6, 2022 02:24
query comparison script
community_ids = [247, 14, 1, 13, 8, 4, 7]
query = Comment.where(
context_type: 'Community', context_id: community_ids
).where.not(
commentable_id: nil, commentable_type: nil
).select(:id, :commentable_id, :commentable_type, :context_id, :context_type)
.includes(:commentable, :context)
mismatches = query.find_each.with_object([]) do |comment, mismatches|
next if comment.commentable.blank?
@caio-nas
caio-nas / binary_gap.rb
Last active July 19, 2017 15:05
Ruby code challenges
=begin
A binary gap within a positive integer N is any maximal sequence of consecutive zeros
that is surrounded by ones at both ends in the binary representation of N.
Write a function:
def solution(n)
that, given a positive integer N, returns the length of its longest binary gap.
The function should return 0 if N doesn't contain a binary gap.
curl -0 -v -XPOST http://localhost:3000/posts.json \
-H "Expect:" \
-H 'Content-Type: application/json; charset=utf-8' \
-d @- << EOF
{
"post": {
"author_id": "5482696809",
"author_name": "@endireitabelem",
"body": "Diretas já em cuba .\n#bolsonaro2018 \n#bolsonaropresidente \n#ForaPT \n#ForaComunistas \n@Endireitabelem \nAjude a pagina a crescer, divulgue com seus amigos e familiares vamos juntos Endireitar Belém e o Brasil.",
"document_id": "BVADte9Ako7m567891101234",
#HTTP error handling
@app_context.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404
from flask import Blueprint
blueprint = Blueprint('web', __name__, template_folder='templates')
from . import routes
# Import a module / component using its blueprint handler variable
from blueprints.hello import blueprint as hello
from blueprints.web import blueprint as web
# Register blueprint(s)
app_context.register_blueprint(hello, url_prefix='/hello')
app_context.register_blueprint(web)
@manager.command
def list_routes():
import urllib
from flask import url_for
output = []
for rule in app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
@caio-nas
caio-nas / rendimentos.html
Last active August 29, 2015 13:58 — forked from anonymous/jsbin.zoqocibi.html
Calculador de rendimentos de investimento em juros compostos
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
select
/* Nomes dos campos ou '*' */
nome,id
/* Tabela de destino */
from setor
/* Filtro (opcional) */
where id = 3;