Skip to content

Instantly share code, notes, and snippets.

@WesleyBatista
WesleyBatista / GithubProvider.py
Last active June 27, 2016 18:13
A class to get file content from github repos
import requests
from requests.auth import HTTPBasicAuth
class GithubProvider(object):
"""docstring for GithubProvider"""
def __init__(self, repo, username, secret_key):
super(GithubProvider, self).__init__()
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
# set the vars
CLIENT_ID=xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CLIENT_SECRET=xxxxxxxxxxxxxxxxxxx
EMAIL=me@mycompany.com
PASSWORD=xxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXX
INSTANCE_URL=https://xxxx.salesforce.com
# request the token
curl -d "grant_type=password&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&username=$EMAIL&password=$PASSWORD" $INSTANCE_URL/services/oauth2/token
@WesleyBatista
WesleyBatista / scala_date_formating.scala
Last active March 14, 2019 20:02
convert timestamp to String in Scala
import java.text.SimpleDateFormat
object TS2Date4 {
def convert():String = {
val ts = System.currentTimeMillis()
val df:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
df.format(ts)
}
}
package com.example.salesforce
/**
* The object to acommodate the main method that will instantiate the `SObject`
*/
object ObjectExporter {
/**
* Get the arguments from the command line, pass to the `SObject` constructor and
* call the `dumpNewlineDelimitedJson` method.
package com.example.salesforce
import java.util.List
import java.io.{BufferedWriter, File, FileWriter}
import org.apache.http.impl.client.{DefaultHttpClient,BasicResponseHandler}
import org.apache.http.client.methods.HttpGet
import com.typesafe.config.ConfigFactory
import com.google.gson.{Gson, JsonParser, JsonArray}
import scala.collection.JavaConversions._
package com.example.salesforce
import java.io._
import org.apache.commons._
import org.apache.http._
import org.apache.http.client._
import org.apache.http.client.methods.HttpPost
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.impl.client.BasicResponseHandler
import org.apache.http.client.ResponseHandler
package com.example.salesforce
import com.google.gson.Gson
import scala.collection.mutable.{Map,
SynchronizedMap, HashMap}
case class DescribeField(name: String, `type`: String)
force {
UserName = "me@mycompany.com"
PassWord = "xxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXX"
ClientID = "xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ClientSecret = "xxxxxxxxxxxxxxxxxxx"
InstanceUrl = "https://xxxx.salesforce.com"
DataServiceUrl = "/services/data/v41.0"
}
@WesleyBatista
WesleyBatista / consumer.py
Last active June 16, 2018 00:42
Kafka 0.11.0.0 with kafka-manager running with docker-compose
import os
from kafka import KafkaConsumer
from settings import BOOTSTRAP_SERVERS, TOPIC
consumer = KafkaConsumer(TOPIC, bootstrap_servers=BOOTSTRAP_SERVERS, auto_offset_reset='earliest')
print("connected to: {}".format(BOOTSTRAP_SERVERS))
for message in consumer:
# message value and key are raw bytes -- decode if necessary!