Skip to content

Instantly share code, notes, and snippets.

View servatj's full-sized avatar
🏠
Working from home

Josep Servat servatj

🏠
Working from home
View GitHub Profile
@servatj
servatj / iterm2.md
Created November 11, 2022 06:19 — forked from squarism/iterm2.md
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
/*
Búsqueda binaria (Binary Search): Implementación de ejemplo.
Recibe un array ordenado y el elemento a buscar. Si encuentra el elemento
devolverá el índice del elemento encontrado, si no se encuentra devolverá `-1`.
*/
function binarySearch(array, item) {
@servatj
servatj / prune-docker.md
Last active July 27, 2022 10:25
Completly prune your dockers

How to prune docker containers

1 - Stop all the containers

docker kill $(docker ps -q)

2 - Run a system prune

@servatj
servatj / Lottery.txt
Last active January 19, 2022 22:27
Simple Lotery smart contract
pragma solidity ^0.4.21;
contract Lottery {
address public manager;
address[] public players;
constructor() public {
manager = msg.sender;
}

Screen Quick Reference

Basic

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r
@servatj
servatj / classInstanceToPlain.js
Created October 29, 2019 11:17
Convert instance class to plain object.
const classToObject = theClass => {
const originalClass = theClass || {}
const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(originalClass))
return keys.reduce((classAsObj, key) => {
classAsObj[key] = originalClass[key]
return classAsObj
}, {})
}
const falsyValues = [undefined, null, 0, '', NaN]
const isTruthy = (value) => !falsyValues.includes(value)
@servatj
servatj / DateRange.scala
Created February 25, 2019 15:33
Scala function for getting a range of dates given a number of days.
val fullDate = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val getDates = (days: Int) => {
val datesList = ListBuffer[String]()
var count: Int = 0;
for (i <- 1 to days) {
datesList += fullDate.format(LocalDate.now().minusDays(i))
}
datesList
}
@servatj
servatj / helperDates.js
Created February 25, 2019 12:16
Get the number of days between to days in JS
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2018,08,13);
var secondDate = new Date(2019,02,25);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
This is only a test
I guees i can add code
```
println("")
```