Skip to content

Instantly share code, notes, and snippets.

@jcaromiq
jcaromiq / add_trait.rs
Created May 5, 2020 22:29
Rust snippets
#[derive(Debug, PartialEq)]
enum Currency {DOLLAR, EURO}
#[derive(Debug, PartialEq)]
struct Money {
currency: Currency,
amount: u8,
}
impl std::ops::Add for Money {
@jcaromiq
jcaromiq / parametrized.rs
Created October 18, 2019 13:43
Example of a macro to parametrized test
#[cfg(test)]
mod tests {
#[macro_export]
macro_rules! parametrized {
($($name:ident: $value:expr,)*) => {
$(
#[test]
fn $name() {
let (input, expected) = $value;
assert_eq!(expected, input);
fun <R> Boolean.fold(whenFalse: R, whenTrue: R) = when (this) {
true -> whenTrue
false -> whenFalse
}
inline fun <R> Boolean.fold(whenFalse: () -> R, whenTrue: () -> R) = when (this) {
true -> whenTrue()
false -> whenFalse()
}
@jcaromiq
jcaromiq / .zshrc
Last active March 14, 2018 09:53
Hook to execute file with name .env.sh if exists when change directory
source_env() {
if [ ! -z "$1" ]; then
1=$(realpath $1)
if [[ "$1" != "/" ]]; then
source_env "$1/.."
env_file="$1/.env.sh"
if [[ -e $env_file ]]; then
source $env_file
fi
fi
@jcaromiq
jcaromiq / project.clj
Last active December 20, 2017 23:41
Clojure leiningen ci-friendly version
(def revision (or (System/getenv "revision") "LOCAL"))
(defproject my-awesome-project revision
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot app.core
:target-path "target/%s"
@jcaromiq
jcaromiq / git_tips
Last active June 12, 2019 19:51
Git tips
#GIT Para ver los cambios que tenemos en los commits pendientes de subir:
git log origin/[master o branch]..HEAD
git diff origin/[master o branch]..HEAD
Ej: git diff origin/feature/featureA..HEAD
Ej: git diff origin/master..HEAD
#Purgar las ramas locales que ya no existan en remoto
@jcaromiq
jcaromiq / delete-docker-images.sh
Last active July 24, 2018 09:52
Docker: Remove all images and containers
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q) -f
@jcaromiq
jcaromiq / CYGWIN_BASH_LIKE_A_BOSS.md
Last active April 24, 2017 20:15
# cygwin bash like a boss
@jcaromiq
jcaromiq / shell.sh
Last active July 13, 2023 11:03
Comprimir y descomprimir .gz, .tar.gz, y .zip por linea de comandos en Linux
Archivos .tar.gz:
Comprimir: tar -czvf empaquetado.tar.gz /carpeta/a/empaquetar/
Descomprimir: tar -xzvf archivo.tar.gz
Archivos .tar:
Empaquetar: tar -cvf paquete.tar /dir/a/comprimir/
Desempaquetar: tar -xvf paquete.tar
Archivos .gz:
Comprimir: gzip -9 index.php
'use strict';
/* Controllers */
function LoginCtrl($scope) {
var parameters = {"scope":"https://www.googleapis.com/auth/plus.login",
"requestvisibleactions": 'http://schemas.google.com/AddActivity',
"clientId":"xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"theme":"dark",