Skip to content

Instantly share code, notes, and snippets.

View pallocchi's full-sized avatar

Pablo Pallocchi pallocchi

View GitHub Profile
@pallocchi
pallocchi / saveNewAttachmentsToDrive.js
Last active July 27, 2024 16:05
Automatically Save Email Attachments to Google Drive Using Google Apps Script
function saveNewAttachmentsToDrive() {
var folderId = "PUT_YOUR_FOLDER_ID_HERE"; // Replace with the ID of the destination folder in Google Drive
var searchQuery = "to:your-email@example.com has:attachment"; // Replace with the search query to find emails with attachments
var lastExecutionTime = getLastExecutionDate();
var threads = GmailApp.search(searchQuery + " after:" + lastExecutionTime);
var driveFolder = DriveApp.getFolderById(folderId);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
@pallocchi
pallocchi / newman-wrapper.sh
Created March 1, 2022 19:38
Running Postman Tests with CI/CD
#!/bin/sh
set -eu pipefail
echo "Attempting to connect to cicd-postman-tests-api"
until $(nc -zv cicd-postman-tests-api 5050); do
printf '.'
sleep 5
done
echo "Connected to cicd-postman-tests-api!"
@pallocchi
pallocchi / docker-compose.yml
Created March 1, 2022 19:37
Running Postman Tests with CI/CD
version: '3'
services:
cicd-postman-tests-api:
container_name: cicd-postman-tests-api
image: vad1mo/hello-world-rest
cicd-postman-tests-newman:
container_name: cicd-postman-tests-newman
image: postman/newman
entrypoint: sh
command: /src/newman-wrapper.sh
@pallocchi
pallocchi / MoviesRepository.kt
Last active September 22, 2018 05:20
Offline full-text search in Android & iOS
fun search(text: String): List<Movie> {
val movies = mutableListOf<Movie>()
val cursor = getDatabase().rawQuery("SELECT title, overview, poster, matchinfo(movies, 'pcnalx') FROM movies WHERE movies MATCH '$text*'", null)
if (cursor.moveToFirst()) {
do {
// Read and prepare matchinfo blob
val matchinfo = cursor.getBlob(3).toIntArray()
// Calculate score based on matchinfo values
// Here I'm only using the first column (title) to calculate the score
@pallocchi
pallocchi / MoviesRepository.swift
Last active August 3, 2018 00:26
Offline full-text search in Android & iOS
func search(text: String) -> [Movie] {
var movies: [Movie] = []
var statement: OpaquePointer?
let query = "SELECT title, overview, poster, year, matchinfo(movies, 'pcnalx') FROM movies WHERE movies MATCH '\(text)*'"
if sqlite3_prepare_v2(db, query, -1, &statement, nil) != SQLITE_OK {
print("Error preparing select: \(String(cString: sqlite3_errmsg(db)!))")
}
@pallocchi
pallocchi / Main.java
Last active March 9, 2017 04:08
Using Java 8 lambdas with Netflix Hystrix
String greet = Underwood.forSingle(String.class)
.withGroup("ExampleGroup")
.withName("ExampleCommand")
.withTimeout(5000)
.withFallback(e -> "Hello anonymous!")
.execute(() -> "Hello " + name + "!");
@pallocchi
pallocchi / Main.java
Created March 9, 2017 03:07
Using Java 8 lambdas with Netflix Hystrix
String s = new CommandHelloWorld("Frank").execute();
@pallocchi
pallocchi / CommandHelloWorld.java
Last active March 9, 2017 03:42
Using Java 8 lambdas with Netflix Hystrix
public class CommandHelloWorld extends HystrixCommand<String> {
private final String name;
public CommandHelloWorld(String name) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("ExampleCommand")))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(5000));
this.name = name;
}
@pallocchi
pallocchi / MainActivity.java
Last active March 6, 2017 02:45
Splash screen in Android: The right way
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
}
}
@pallocchi
pallocchi / AndroidManifest.xml
Created March 6, 2017 02:17
Splash screen in Android: The right way
<activity android:name=".activities.MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>