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
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active December 18, 2023 08:10
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;
@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
@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
# 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),
@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
@modeswitch
modeswitch / gist:114c9bd55d800df242a2
Last active June 19, 2020 17:16
Building Node.js for Anddoid

Before you begin

Make sure you have adb installed and that it works. Test this by connecting your phone and running adb devices. In order to proceed past the build stage, your device must be rooted. The device I used is running Cyanogenmod with root enabled for both apps and adb.

Build

Fetch the Android NDK

You'll need to get the Android NDK. I used r8e, which you can get from here: http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86.tar.bz2. Make sure you get the x86 version, as the x86_64 version will not help you. Let's call the path where you unpack this NDK_PATH.

@corydolphin
corydolphin / mongoengine_jsonencoder.py
Last active August 9, 2021 17:57
Fix: TypeError: ObjectId is not JSON serializable: A Flask JSONEncoder for Mongoengine documents. Specifically useful for use with Flask-Mongoengine.
from flask import Flask
from flask.json import JSONEncoder
from bson import json_util
from mongoengine.base import BaseDocument
from mongoengine.queryset.base import BaseQuerySet
class MongoEngineJSONEncoder(JSONEncoder):
def default(self,obj):
if isinstance(obj,BaseDocument):
return json_util._json_convert(obj.to_mongo())
@lukaszb
lukaszb / notify.py
Created February 21, 2013 01:23
Simple Python script to send notification to the OSX Notifications Center (requires OS X 10.8+). Tested with pyobjc 2.5.1
#!/usr/bin/env python
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from Foundation import NSUserNotificationDefaultSoundName
from optparse import OptionParser
def main():
parser = OptionParser(usage='%prog -t TITLE -m MESSAGE')
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@turtlesoupy
turtlesoupy / nginx.conf
Created July 8, 2012 21:16
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;