Skip to content

Instantly share code, notes, and snippets.

View williamokano's full-sized avatar
🎯
println("Kotlin is nice")

William Okano williamokano

🎯
println("Kotlin is nice")
View GitHub Profile
import java.util.*
infix fun <R> (() -> R).times(times: Int): List<R> = times.takeIf { it > 0 }
?.let { (1..it) }
?.map { this() }
?: emptyList()
inline infix operator fun <R> Int.times(block: () -> R): List<R> = this.takeIf { it > 0 }
?.let { (1..this) }
?.map { block() }
@williamokano
williamokano / gpg-import-and-export-instructions.md
Created September 24, 2019 20:43 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

<?php
class SomeHelper
{
private static function totalPorPeriodo($confirmado, $campo, $valor)
{
$dataIni = session('dataIni', date('Y-m-01'));
$dataFim = session('dataFim', date('Y-m-t'));
$contasPagas = DB::table('saidas')
->selectRaw('sum(valor) as total')
<?php
function array_compare($target, $source)
{
if (count($target) != count($source)) {
return false;
}
foreach ($target as $key => $value) {
if ($target[$key] != $source[$key]) {
fun main(args: Array<String>) {
/*
val input = mapOf(
"Pete" to "Nick",
"Sophie" to "Jonas",
"Barb" to "Nick",
"Nick" to "Sophie"
)
*/
@williamokano
williamokano / sample.sql
Last active July 7, 2019 18:28
Example order with last status
-- table customers
create table
customers ( id serial not null primary key,
name varchar(64) not null );
-- seed customers
insert
into
customers (name)
@williamokano
williamokano / CustomerServiceTest.groovy
Created July 6, 2019 23:28
Testing examples with Java and Spock
// imports
class CustomerServiceTest extends Specification {
def repository = Mock(CustomerRepository)
def service = new CustomerService(repository)
def "should create customer"() {
given:
def customerId = UUID.randomUUID().toString()
def customer = buildCustomer(customerId)
@williamokano
williamokano / FirstUniqueCharacterResolver.java
Last active July 1, 2019 02:56
First non repeating character from string
package dev.william.java.sample;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
public class FirstUniqueCharacterResolver {
private final String inputString;
private final LinkedHashMap<Character, Integer> map;
<?php
class FooController {
public function create() {
$data = json_decode(request()->data, true);
$allDataObjects = array_map([$this, 'saveData'], $data);
// do something
return ['status' => 'ok'];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<img src='data:image/png; data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAATQAAADhCAYAAABGBUm3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAJOgAACToAYJjBRwAAB1sSURBVHhe7d0JeFTV2Qfwd2ay7xtZCVsCBAh7ILgDgtL6VUWKbGpBtK0F6QaKKFpbUKuiohZQqiIV1IpQEFD5VKyKEvbIEgMBWcxkgYSQdSaTmXxz5nt5ajUhk5l7Z869+f945sl5z0SZScg/99x77jmGZicCANABI38EANA8BBoA6AYCDQB0A4EGALqBQAMA3UCgAYBuINAAQDcQaACgGwg0ANANae4UaG5qImtZGdktFmq22cgQGEimkBAKSkwko7MNANAWvwWatbSUqvJ2Uc3hQ1Rz0PkoKKDmxkZ+9j8MQUEUkZVFkf37U2R2P4oZNoxCUlP5WQCA//BpoIm/qiovj4rXrKGKT7aLDn6mfeJHjaK0adMo5rIRZDAYuFc5liYLVTZUkQyHrtHBkRQRFM5V+4j30OB8L/4WYDRRfGic62N7VefnU/nWrdRUXePxv5fva5biu6osg/MPmUxkMBrJ6BzVBEZHU2CM8xEbSwExMc52DAUnJ1NQfDz/F/rlk0ATf0X55s10+uWVVH/8OPd6L7R7d+ryy7sp6cYbFQk2EWRLd6+kLUUfkdVu5V7/MhqMNLLL5fSH3HuoU5h7/yC/Lj/ieh+HzhZwj/8lOAPt9v4TaVKfm93+XhU9/jgV/+MNrsBbAc6gC8vIoHDnw/WxV0+KGjTIdWpHL1QPNOvZs3TskT9Rxaefco/y4q6+inr9+c8U