Skip to content

Instantly share code, notes, and snippets.

View vitorleal's full-sized avatar
🚀
ready to deploy

Vitor Leal vitorleal

🚀
ready to deploy
View GitHub Profile
@mattlong
mattlong / admin.py
Created September 17, 2014 18:26
Add a custom admin page for a model and link to it from the detail page
from functools import update_wrapper
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.core.exceptions import PermissionDenied
from django.shortcuts import render
from myapp.models import Widget
from myapp.forms import ManageWidgetForm
# defmodule Repo.Migrations.LogsHTTP do
# use Ecto.Migration
# def up do
# execute """
# CREATE TABLE logs_http(
# id serial primary key,
# request_id varchar(200),
# method varchar(8),
# path varchar(128),
@ezefranca
ezefranca / SPTransOlhoVivo.swift
Last active February 17, 2017 10:06
Acesso a API Olho Vivo da SPTrans em Swift (iOS)
+(NSString *)returnURL: (requestMethodGET)methodGET line:(id)line{
NSString *SPTrans = @"http://api.olhovivo.sptrans.com.br/v0";
switch (methodGET) {
case requestMethodGETLinhas: return [NSString stringWithFormat:@"%@/Linha/Buscar?termosBusca=%@", SPTrans, line]; break;
case requestMethodGETDetalhes: return [NSString stringWithFormat:@"%@/Linha/CarregarDetalhes?codigoLinha=%@", SPTrans, line] ;break;
case requestMethodGETParadas: return [NSString stringWithFormat:@"%@/Parada/Buscar?termosBusca=%@", SPTrans, line] ;break;
case requestMethodGETParadasPorLinha: return [NSString stringWithFormat:@"%@/Parada/BuscarParadasPorLinha?codigoLinha=%@", SPTrans, line] ;break;
case requestMethodGETParadasPorCorredor: return [NSString stringWithFormat:@"%@/Parada/BuscarParadasPorCorredor?codigoCorredor=%@", SPTrans, line] ;break;
case requestMethodGETCorredores: return [NSString stringWithFormat:@"%@/Corred
@trojanh
trojanh / Transformer.ex
Last active March 16, 2022 07:35
Create Image thumbnail using ImageMagick in Elixir
defmodule Image.Transformer do
def transform(original_file, operation \\ "convert") do
thumb_path = generate_thumb_file(original_file)
System.cmd(operation, operation_commands(original_file_path, thumb_path))
thumb_path
end
defp generate_thumb_file(original_file) do
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active February 4, 2025 19:16
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;