Skip to content

Instantly share code, notes, and snippets.

View joaoffcosta's full-sized avatar

João Costa joaoffcosta

View GitHub Profile
@joaoffcosta
joaoffcosta / vectorAngle
Created December 4, 2012 16:20
Angle of a vector
// angle of a vector (defined as AB)
float R2Point::angle(R2Point A, R2Point B)
{
// tg(o) = y / x
float diffy = B.y - A.y;
float diffx = B.x - A.x;
float ang = 0;
// special case;
if ((diffy == 0) & (diffx == 0))
@joaoffcosta
joaoffcosta / gist:5728483
Created June 7, 2013 10:42
How to use S3 browser upload using POST form without leaving the page and with error and success handling
<html>
<head>
<title>S3 POST Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
function canAccessIFrame(iframe) {
var html = null;
try {
@joaoffcosta
joaoffcosta / gist:5729398
Created June 7, 2013 13:49
How to use S3 browser upload using XMLHttpRequest
<html>
<head>
<title>S3 POST Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
var bucketName = 'MY_BUCKET_NAME';
var AWSKeyId = 'MY_AWS_KEY_ID';
var policy = 'MY_POLICY';
var signature = 'MY_SIGNATURE';
@joaoffcosta
joaoffcosta / read_file.html
Created July 1, 2013 16:27
Reading a file selected by the user
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<style>
#progress_bar {
margin: 10px 0;
padding: 3px;
border: 1px solid #000;
@joaoffcosta
joaoffcosta / static_server.js
Last active December 21, 2015 18:29 — forked from ryanflorence/static_server.js
Adds logs, reviews code alignment and fixes path.exists
var http = require("http");
var url = require("url");
var path = require("path");
var fs = require("fs");
var port = process.argv[2] || 8000;
http.createServer(function(request, response) {
console.log(request["method"] + " " + request["url"]);
var uri = url.parse(request.url).pathname;
@joaoffcosta
joaoffcosta / heroku_backup_db.sh
Last active August 29, 2015 14:18
Download latest Heroku DB backup
if [ "$1" = "" ]; then
echo Missing params: heroku-app-name
exit 1
fi
if [ "$2" = "" ]; then
echo Missing params: dump-prefix
exit 1
fi
#!/usr/bin/env ruby
require "yaml"
CONFIG = "~/database.yml"
CONFIG_PARAMS = %w(protocol host port database username password).map(&:to_sym)
def say(channel=:info, msg)
puts "[#{channel.to_s.upcase}] #{msg}"
end
@joaoffcosta
joaoffcosta / UIColor-TextColor.swift
Created November 19, 2018 14:54
UIColor+TextColor
import Foundation
import UIKit
extension UIColor {
convenience init(hex: String) {
let scanner = Scanner(string: hex)
scanner.scanLocation = 1
var rgb: UInt64 = 0
scanner.scanHexInt64(&rgb)
self.init(rgb: Int(rgb))