Skip to content

Instantly share code, notes, and snippets.

Avatar
⚒️
Building

Felipe Lima felipecsl

⚒️
Building
View GitHub Profile
@felipecsl
felipecsl / install-redistimeseries.sh
Last active Sep 17, 2020
Install Redis time series on Amazon Linux
View install-redistimeseries.sh
#!/bin/bash
wget http://downloads.sourceforge.net/ltp/lcov-1.14-1.noarch.rpm
sudo yum localinstall lcov-1.14-1.noarch.rpm
git clone --recursive https://github.com/RedisTimeSeries/RedisTimeSeries.git
cd RedisTimeSeries
sudo make setup
@felipecsl
felipecsl / install-redis.sh
Created Sep 17, 2020 — forked from jpickwell/install-redis.sh
Installing Redis 6.0.0 on Amazon Linux
View install-redis.sh
#!/bin/bash
###############################################
# To use:
# chmod +x install-redis.sh
# ./install-redis.sh
###############################################
version=6.0.8
@felipecsl
felipecsl / FakeResourceHttpURLConnection.kt
Last active Jul 11, 2020
Kotlin snippets for return a canned response from a resource file whenever a URL is request is fired
View FakeResourceHttpURLConnection.kt
// Based on https://stackoverflow.com/questions/565535/mocking-a-url-in-java
package com.example
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
class FakeResourceHttpURLConnection(
url: URL,
@felipecsl
felipecsl / retryIfThrown.kt
Last active Jun 22, 2020
Kotlin utility to retry a provided block a limited number of times
View retryIfThrown.kt
/**
* Retries the provided [block] up to [times] times if the block throws an exception of the type
* [exceptionType]. If any other exception type is thrown, the exception is caught and then
* immediately rethrown.
*/
fun retryIfThrown(times: Int, exceptionType: KClass<out Throwable>, block: () -> Unit) {
for (i in 0 until times) {
try {
block()
break
@felipecsl
felipecsl / setup.sh
Last active Jun 4, 2020
Base EC2 instance setup for Amazon Linux box
View setup.sh
# Install all the packages
sudo yum install -y \
curl gpg gcc gcc-c++ make git \
openssl-devel readline-devel libcurl-devel \
zlib-devel postgresql-server.x86_64 ruby-devel \
sqlite sqlite-devel ruby-rdoc python-devel \
cairo-devel libffi-devel python-pip nc docker \
tmux htop postgresql-libs postgresql-devel \
java-1.8.0-openjdk
View install-ffmpeg-amazon-linux.sh
sudo yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel -y
mkdir ~/ffmpeg_sources
# nasm
cd ~/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
tar xjvf nasm-2.14.02.tar.bz2
cd nasm-2.14.02
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
@felipecsl
felipecsl / phone-number-combinations.rs
Created Apr 15, 2018
My first Rust program - Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
View phone-number-combinations.rs
// https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/
use std::collections::HashMap;
use std::char;
use std::iter::FromIterator;
fn main() {
let mappings = init_map();
find_combinations("23", mappings)
}
View longest-substring.rb
def length_of_longest_substring(str)
if str.empty?
return 0
end
map = {}
curr_start = 0
max_length = 0
found_start = 0
found_end = 0
i = 0
@felipecsl
felipecsl / unless.kt
Last active Dec 24, 2017
Kotlin unless like Ruby just for fun
View unless.kt
inline fun <T> unless(stmt: () -> Boolean, block: () -> T, noinline elseBlock: (() -> T)? = null) =
if (!stmt.invoke()) {
block()
} else {
elseBlock?.invoke()
}
// Use like:
unless({ foo == bar }, {
@felipecsl
felipecsl / extensions.kt
Last active Jan 30, 2018
Helpful Kotlin extension functions
View extensions.kt
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import org.gradle.api.Task
import org.gradle.api.Project
import org.gradle.api.UnknownTaskException
import org.gradle.api.GradleException
import org.gradle.api.plugins.ExtraPropertiesExtension
@SuppressWarnings("UNCHECKED_CAST")
fun <T> Project.ext(key: String): T {
You can’t perform that action at this time.