Skip to content

Instantly share code, notes, and snippets.

View rodolfo42's full-sized avatar
🎧

Rodolfo Ferreira rodolfo42

🎧
View GitHub Profile
@rodolfo42
rodolfo42 / README.md
Last active January 19, 2018 09:33
Post current playing Spotify song to a txt online (MacOS)

How to use it

$ curl -s https://gist.githubusercontent.com/rodolfo42/c4a04cb5757ffb4bac1a02db54a5fa07/raw/f90e69d91f01f4096d7dc4556f810a3853efde27/spotifynowplaying.sh > ~/spotifynowplaying.sh

Change the URL

Change URL to some dontpad.com url (it's a simple persistent textarea in the cloud)

@rodolfo42
rodolfo42 / batch-write.js
Created August 8, 2017 14:20
DynamoDB streams lambda trigger
const items = [{
"Username": "First",
"Timestamp": "2017-08-07T19:51:00.794Z",
"Message": "first item in batch"
},
{
"Username": "Second",
"Timestamp": "2017-08-07T19:51:00.794Z",
"Message": "second item in batch"
},
@rodolfo42
rodolfo42 / dependency-injection-example.md
Last active April 24, 2017 14:12
Example of dependency injection with modules

@team/corelib library

lib/stats.js

This is a stats lib that has no dependencies but needs to be initialized.

module.exports = function initializeStats(projectName, options) {
  return {
@rodolfo42
rodolfo42 / tabs_to_spaces.sh
Created April 12, 2017 19:30
tabs to spaces recursive
mkdir -p exp &&\
ls -1 | grep -v exp | xargs -I '@' cp -aRv @ exp/@ &&\
find * -type f | grep -e '\.\(html\|scss\|css\|js\)$' | grep -ve '^exp' |\
xargs -tn1 -I file bash -c 'expand -t 2 file > exp/file' &&\
cp -avR exp/* . &&\
rm -rf exp
@rodolfo42
rodolfo42 / diffs.js
Last active April 12, 2017 15:00
Yield differences in parsing dates from log vs event log timestamp
const moment = require('moment');
const format1 = require('./format1_log_events.json');
const format2 = require('./format2_log_events.json');
const events = {
format1,
format2
};
@rodolfo42
rodolfo42 / yaml_to_json.sh
Last active July 15, 2016 15:32
Convert a YAML to JSON
ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < in.yml > out.json
@rodolfo42
rodolfo42 / Test.scala
Created May 30, 2015 02:29
Http RequestBuilder is not correctly configured
object Test extends App {
val url = "http://google.com/search"
val query = ("q", "finagle")
val request = com.twitter.finagle.http.RequestBuilder()
.url(url)
.addFormElement(query)
.buildGet()
println(request)
}
@rodolfo42
rodolfo42 / Db.scala
Last active January 17, 2018 15:23
How to use transactions with finagle-mysql
package transactions
import com.twitter.finagle.exp.mysql.{Client, OK, Result}
class Db(mysqlClient: Client) {
val insertOrder = "INSERT INTO orders (ref) VALUES(?)"
val insertOrderItem = "INSERT INTO order_items (order_id, item_id) VALUES(?, ?)"
def persistOrderWithItems[T](order: Order)(whenDone: (OK, Seq[Result]) => T): Future[T] = {
@rodolfo42
rodolfo42 / Either.scala
Created November 25, 2014 17:00
Try vs Either
// 1: Handler
def handle(req: Request): Response = {
val indexes = req.get("indexes")
service(indexes)
.map(Response(json(_)))
.orElse(Response.badRequest)
}
// 2: Service
import rapture._
import core._, io._, net._, uri._, json._, codec._
import jsonBackends.jawn._
import encodings.`UTF-8`
object Test extends App {
// entities
case class Bands(groups: Seq[Band])