Skip to content

Instantly share code, notes, and snippets.

@potfur
potfur / Main.kt
Last active December 20, 2018 14:44
AWS Lambda : Kotlin
package example
import com.amazonaws.services.lambda.runtime.Context
import java.io.*
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.*
@JsonIgnoreProperties(ignoreUnknown = true)
data class ALBRequest(
val requestContext: Map<String, Map<String, String>>,
@potfur
potfur / example.sql
Last active May 1, 2020 16:16
PSQL views from json array
-- Non blocking index creation
CREATE INDEX CONCURRENTLY ix_transaction_created_at_status_buyer ON transaction (created_at, status, (seller->>'id'::text));
-- Index usage
SELECT
t.schemaname,
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(t.tablename)::text)) AS table_size,
@potfur
potfur / build.gradle
Created November 23, 2016 13:30
build.gradle template
group 'group name'
version '0.0.0'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
sourceCompatibility = 1.8
mainClassName = "Main"
interface UserRegistrationVerification
{
public function execute(User $user);
}
final class NoVerification implements UserRegistrationVerification
{
public function execute(User $user)
{
@potfur
potfur / bcryptcost.php
Created September 17, 2015 08:59
bcrypt cost calculator
<?php
$mooreLawConst = 18;
$defaults = 6; // from initial implementation for normal user
$monthsFromPublication = (new \DateTime('1999-12-31'))->diff(new \DateTime());
$monthsFromPublication = $monthsFromPublication->y * 12 + $monthsFromPublication->m + round($monthsFromPublication->d / 31);
$cost = $defaults + $monthsFromPublication / $mooreLawConst;
var_dump($cost);
public Integer max(Integer a, Integer b) {
return new If(
new GreaterThan(a, b),
a, b
);
}
Array(16).join("foo" - 1) + " Batman!"
@potfur
potfur / gist:8954044
Last active August 29, 2015 13:56
Self nesting category [nested set]
<?php
namespace gist;
/**
* Self nesting node
* Can use parent_id/order or left/right nested set or convert one to another
*
* @package gist
* @author Michal Wachowski <wachowski.michal@gmail.com>
*/
@potfur
potfur / gist:8556591
Created January 22, 2014 10:32
simple map reduce
<?php
error_reporting(-1);
// reader
// reads n per call starting from last position til EOF
$offset = 0;
$reader = function ($n = 100) use (&$offset) {
$limit = $offset + $n;
$ln = 0;
$content = array();
@potfur
potfur / $.js
Last active February 15, 2023 14:49
window.S = function(s) {
return document[{
'#': 'getElementById',
'.': 'getElementsByClassName',
'@': 'getElementsByName',
'=': 'getElementsByTagName'}[s[0]]
|| 'querySelectorAll'](s.slice(1))
};
// [S('#header'), S('.container'), S('?div')]