Skip to content

Instantly share code, notes, and snippets.

View joaofnds's full-sized avatar

João Fernandes joaofnds

View GitHub Profile
@joaofnds
joaofnds / nginx.vhost
Last active November 5, 2016 15:07 — forked from vedovelli/nginx.vhost
server {
listen 80;
server_name CHANGEME.app;
root /var/www/vhosts/CHANGEME.app/public;
index index.html index.htm index.php;
charset utf-8;
location / {
<?php
//1) Preferred
"text {$array['name']} more text"; // associative single
"text $array[2] more text"; // numeric single
"text $object->name $object->price more text"; // property
//2) Valid alternatives
"text $array[name] more text"; // associative single
"text {$array[2]} more text"; // numeric single
@joaofnds
joaofnds / dijkstra.cr
Last active August 15, 2017 16:42
Simple Dijkstra shortest path algorithm implementation using Crystal
struct Vertex
property id, edges
def initialize(@id : Int32)
@edges = Hash(Pointer(Vertex), Float64).new
end
end
def find(graph : Array(Pointer(Vertex)), start : Pointer(Vertex), end : Pointer(Vertex))
dist = {} of Pointer(Vertex) => Float64 # Distances
prev = {} of Pointer(Vertex) => Pointer(Vertex) # Path
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define TABLE_SIZE 100
#define WORD_SIZE 100
struct node {
char * key;
int value;
#include <cstdio>
#include <iostream>
using namespace std;
inline int char_to_index(char c) { return c - 'a'; }
inline char index_to_char(int index) { return 'a' + index; }
int main(void) {
int vertices_number = 0, edges_number = 0, test_case_number = 5;
#include <stdio.h>
#include <stdlib.h>
struct node {
int rank;
char data;
struct node* parent;
};
struct node* create_node(char data);
#include <cmath>
#include <iostream>
#include <queue>
#include <iomanip>
using namespace std;
typedef pair<int, int> coords;
inline double vector__length(coords pos) {
@joaofnds
joaofnds / sql-describe.go
Last active January 3, 2018 09:30
Performs a SQL "DESCRIBE database;" command in go using the database/sql and go-sql-driver/mysql packages
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
@joaofnds
joaofnds / Dockerfile
Last active July 16, 2018 14:01
Dockerfile for joaofnds/rails-alpine
FROM ruby:alpine
# Minimal requirements to run a Rails app
RUN apk add --no-cache --update build-base \
linux-headers \
git \
postgresql-dev \
tzdata \
nodejs
@joaofnds
joaofnds / Dockerfile
Created July 16, 2018 14:01
multi-stage rails build based on ruby:alpine
FROM joaofnds/rails-alpine as builder
RUN mkdir /app
WORKDIR /app
COPY Gemfile Gemfile.lock /app/
RUN bundle install
FROM joaofnds/rails-alpine
RUN mkdir /app
WORKDIR /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/