Skip to content

Instantly share code, notes, and snippets.

View Miuler's full-sized avatar
🦀
Mi nueva pacion, Rust!

Hector Miuler Malpica Gallegos Miuler

🦀
Mi nueva pacion, Rust!
View GitHub Profile
@Miuler
Miuler / connect_bluetooth_headphones.sh
Created September 28, 2020 15:52 — forked from egelev/connect_bluetooth_headphones.sh
Connect bluetooth headphones on Ubuntu 18.04
#!/usr/bin/env bash
function get_headphones_index() {
echo $(pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}')
}
function get_headphones_mac_address() {
local temp=$(pacmd list-cards | grep bluez_card -C20 | grep 'device.string' | cut -d' ' -f 3)
temp="${temp%\"}"
temp="${temp#\"}"
@ryanlecompte
ryanlecompte / gist:5210745
Last active August 25, 2021 13:40
mutable.ArrayBuffer vs immutable.Vector
import scala.collection._
import com.twitter.util._
scala> val buffer = mutable.ArrayBuffer.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { buffer += _ } }.inMillis)
17610
scala> var vector = immutable.Vector.empty[Int]
scala> println(Time.measure { (0 to 50000000).foreach { vector :+= _ } }.inMillis)
7865
@alexanderjarvis
alexanderjarvis / Tuple2Format.scala
Created January 22, 2013 15:05
Allow case classes with Tuple2 types to be represented as a Json Array with 2 elements e.g. (Double, Double)
import play.api.libs.json._
import play.api.libs.functional.syntax._
import play.api.data.validation._
implicit def tuple2Reads[A, B](implicit aReads: Reads[A], bReads: Reads[B]): Reads[Tuple2[A, B]] = Reads[Tuple2[A, B]] {
case JsArray(arr) if arr.size == 2 => for {
a <- aReads.reads(arr(0))
b <- bReads.reads(arr(1))
} yield (a, b)
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("Expected array of two elements"))))
@wspringer
wspringer / gist:1649700
Created January 20, 2012 21:28
LZW Encoding *and Decoding* in Scala
object lzw {
trait Appendable[T] {
def append(value: T)
}
import scala.collection.generic._
case class GrowingAppendable[T](growable: Growable[T]) extends Appendable[T] {
def append(value: T) {
growable += value
@newhouseb
newhouseb / gist:1620133
Created January 16, 2012 10:20
MySQL vs PostgreSQL Schema changes benchmarks
The basic idea here is to substantiate the claims made by this square post:
http://corner.squareup.com/2011/06/postgresql-data-is-important.html
In PostgreSQL, and MySQL (MyISAM and InnoDB) I create millions of rows and then add
and remove columns and add and remove indexes. For columns without defaults this is
basically free in PostgreSQL and O(n) in MySQL. For adding indexes its at best O(n)
everywhere, but with PostgreSQL it claims not to do any locking that would otherwise
prevent table interaction.
Also, PostgreSQL has _awsome_ documentation (it has real examples!). I always get