Skip to content

Instantly share code, notes, and snippets.

View felipecrv's full-sized avatar

Felipe Oliveira Carvalho felipecrv

View GitHub Profile
### Keybase proof
I hereby claim:
* I am philix on github.
* I am felipeoc (https://keybase.io/felipeoc) on keybase.
* I have a public key whose fingerprint is 966B E9AC DAD9 4616 ABC9 A3C8 0BBA AF18 42EB 67DC
To claim this, I am signing this object:
#include <cstdio>
#include <algorithm>
using namespace std;
static const int QSORT_BUFLEN = 3;
static int qsort_buf[QSORT_BUFLEN];
static int qsort_bufn; // quantidade de itens no buffer
static void partition(
int* file,
@felipecrv
felipecrv / ct
Created May 11, 2012 04:09
CSS for ctags
--langdef=css \
--langmap=css:.css \
--regex-css='/^[ \t]*\.([A-Za-z0-9_-]+)/#\1/c,class,classes/' \
--regex-css='/^[ \t]*#([A-Za-z0-9_-]+)/.\1/i,id,ids/' \
--regex-css='/^[ \t]*(([A-Za-z0-9_-]+[ \t\n,]+)+)\{/\1/t,tag,tags/' \
--regex-css='/^[ \t]*@media\s+([A-Za-z0-9_-]+)/\1/m,media,medias/' \
@felipecrv
felipecrv / Option.php
Created November 5, 2013 01:12
The Maybe Monad [1] in PHP inspired by Scala's implementation of this concept which they call Option [2]. [1] http://en.wikipedia.org/wiki/Monad_%28functional_programming%29#The_Maybe_monad [2] http://www.scala-lang.org/api/current/scala/Option.html
<?php
interface Option/*[T]*/ {
/**
* @return T
*/
public function get();
/**
* @param => T $f
val sixInts = List(1, 2, 3, 4, 5, 6)
for {
x <- sixInts
y <- sixInts
if x % 2 == 0 && y % 2 == 0
} yield (x, y)
@felipecrv
felipecrv / HttpApiClient.scala
Last active April 8, 2018 13:56
A convenient HTTP API Client based on the Jetty HTTP client written in Scala
package m79.infra
import java.net.URI
import java.time.format.DateTimeFormatter
import m79.infra.HttpAPIClient.Call
import org.eclipse.jetty.client.HttpClient
import org.eclipse.jetty.client.api.{Request, Result}
import org.eclipse.jetty.client.util.{BufferingResponseListener, MultiPartContentProvider, StringContentProvider}
import org.eclipse.jetty.http.HttpMethod
@felipecrv
felipecrv / SimpleImage.php
Created May 31, 2013 21:15
A PHP Imagick wrapper class that makes image manipulation simpler by making some decisions and by adding new functionality. The `getMainBorderColor()` method is specially interesting. With it you can calculate which color is the most frequent in the lateral borders of an image. I used it to set a background for an area that could possibly be lef…
<?php
class SimpleImage {
private $img;
public function __construct($path) {
$path = Filesystem::resolvePath($path);
Filesystem::assertExists($path);
@felipecrv
felipecrv / Sampling.scala
Last active July 19, 2018 19:14
Sampling and Shuffling sequences in Scala
package m79.random
import java.util.Random
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Sampling {
/**
* Randomly sample up to k items from a sequence.
@felipecrv
felipecrv / SBTTestEngine.php
Created September 11, 2018 21:30
sbt Test Engine for Arcanist/Phabricator #scala
<?php
final class SBTTestEngine extends ArcanistUnitTestEngine {
const SBT_ROOT = 'services';
public function getEngineConfigurationName() {
return 'sbt';
}
protected function supportsRunAllTests() {
#! /bin/bash
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT
#-------------------------------------------------------------------------------------------
# This script will download packages for, configure, build and install a GCC cross-compiler.
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
# If you get an error and need to resume the script from some point in the middle,
# just delete/comment the preceding lines before running it again.