Skip to content

Instantly share code, notes, and snippets.

View rbreve's full-sized avatar

Roberto Brevé rbreve

  • Finland
View GitHub Profile
@rbreve
rbreve / docker-compose.yml
Created March 10, 2020 09:38
Docker Tutorial: Adminer + Mysql (with root password hunter)
version: '3.7'
services:
adminer:
image: adminer
ports:
- 8080:8080
links:
- "mysql:db"
//
// FetchView.swift
//
// Created by Roberto Breve on 4.10.2019.
// Copyright © 2019 Roberto Breve . All rights reserved.
//
import Foundation
import SwiftUI
import Combine
struct ContentView: View {
@ObservedObject var fetcher = MovieFetcher()
var body: some View {
VStack {
List(fetcher.movies) { movie in
VStack (alignment: .leading) {
Text(movie.name)
Text(movie.released)
.font(.system(size: 11))
public class MovieFetcher: ObservableObject {
@Published var movies = [Movie]()
init(){
load()
}
func load() {
let url = URL(string: "https://gist.githubusercontent.com/rbreve/60eb5f6fe49d5f019d0c39d71cb8388d/raw/f6bc27e3e637257e2f75c278520709dd20b1e089/movies.json")!
struct Movie: Decodable, Identifiable {
public var id: Int
public var name: String
public var released: String
enum CodingKeys: String, CodingKey {
case id = "id"
case name = "title"
case released = "year"
}
[{
"id": 5,
"title": "Joker",
"year": "2019",
"image": "",
"created_at": "2019-10-06T17:55:21.374Z",
"updated_at": "2019-10-06T17:55:21.374Z"
}, {
"id": 1,
"title": "Pulp Fiction",
@rbreve
rbreve / elevator.js
Created April 17, 2019 13:42
Elevator Saga 1-12
{
init: function(elevators, floors) {
var requests= [];
elevators.forEach(function(e) {
e.on("stopped_at_floor", function(floorNum) {
if(floorNum===0) {
e.destinationQueue.sort(function(a, b){return a-b});
pragma solidity ^0.4.21;
contract Lempira {
address public bancoCentral;
uint public supply;
mapping (address => uint) public saldos;
event Enviado(address desde, address hacia, uint valor);
@rbreve
rbreve / voting.sol
Last active October 13, 2018 09:43
Ejemplo de Smart Contract de Voto Electrónico
pragma solidity ^0.4.0;
contract Election{
struct Candidato {
uint id;
string nombre;
uint votos;
}
@rbreve
rbreve / DeviseJSON.md
Last active August 28, 2018 05:34
JSON Devise Authentication avoid "Can't verify CSRF token authenticity" Rails 5.x

To be able to authenticate a user using JSON using Devise you need to bypass the CSRF token warning that Rails throws when signing in with JSON, this is useful when trying to use a mobile app that will consume your app api and authenticate. The documention to solve this problem is outdated on google or stack overflow. Rails 5 did some changes, this is how to do it.

Add this on the Application Controller

protect_from_forgery unless: -> { request.format.json? }

More info here

Add this to the Devise SessionController