Skip to content

Instantly share code, notes, and snippets.

View rodolfo42's full-sized avatar
🎧

Rodolfo Ferreira rodolfo42

🎧
View GitHub Profile
@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 / 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 / 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 / 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 / README.md
Created April 30, 2018 09:47
Fix for "symbol cannot be resolved" for Cursive + Midje

Fix for 'symbol cannot be resolved' when using Cursive + midje

Midje checkers (e.g. n-of, has, match from matcher-combinators) cannot be resolved when using Cursive because they are declared using the defchecker macro.

To make Cursive able to resolve these references as valid symbols, follow these steps:

  1. Download the defchecker.xml file somewhere in your machine
  2. In Cursive (IntelliJ) Preferences pane, navigate to Languages & Frameworks > Clojure > Symbol Resolution
  3. Click the cog icon, select Import Scheme... and choose the file you downloaded.
  4. Click Apply. Note: all open projects will be refreshed and re-indexed, so go get a coffee ☕
@rodolfo42
rodolfo42 / watch.clj
Created August 29, 2018 14:27
watch files for changes and reload namespaces
(require '[io.pedestal.service-tools.dev :as dev-tools])
(def ^:private watcher (atom nil))
(defn stop-watching []
(let [stop @watcher]
(when (fn? stop) (stop) (reset! watcher nil))))
(defn watch
([] (watch ["src/"]))
@rodolfo42
rodolfo42 / getOrElse.js
Created March 14, 2014 18:40
simple getOrElse in javascript
function getOrElse(value, _) {
var args = Array.prototype.slice.call(arguments);
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if(typeof arg != "undefined" && arg != null && !isNaN(arg)) {
return arg;
}
}
return null;
}
@rodolfo42
rodolfo42 / code.js
Last active April 9, 2020 02:42
Bookmarklet to organize status checks in bors
function appendRow(el, test, status, link) {
var testName = document.createElement("div");
var statusCell = document.createElement("div");
statusCell.innerText = status;
var order = (status == "Succeeded" ? 10 : 5);
testName.style = "flex-basis: 50%; flex-grow: 2; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px dashed #666; order: " + order + ";";
statusCell.style = "flex-grow: 1; text-align: right; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px dashed #666; order: " + order + ";";
if (link) {
var a = document.createElement("a");
a.innerText = test;
@rodolfo42
rodolfo42 / tomcat.sh
Last active May 13, 2020 06:02
Apache Tomcat 7 service init script
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Apache Tomcat 7
### END INIT INFO
# base dir of tomcat installation #
CATALINA_HOME=/opt/tomcat/
@rodolfo42
rodolfo42 / README.md
Last active April 20, 2021 02:00
Completed JSON

For when you have incomplete JSON strings like:

{"Fault":
  {"faultcode": "StartTransmissionFail",
   "faultstring": {"content": "Internal Error"

Given an incomplete JSON-encoded string, attempts to complete it with the missing ", } and ] characters necessary for it to be valid.