Skip to content

Instantly share code, notes, and snippets.

@srigi
srigi / gist:795f286bb67a031d918c5b969ca6e54c
Created May 10, 2023 12:36
Typescript discriminated union with non-mutual prop
type T =
| { x: true, y: string | null }
| { x?: never, y: string }
or
if ("x" in t) {
console.log(t.x)
@srigi
srigi / ConsumerCommand.php
Created February 15, 2018 12:08
PHP rdkafka
<?php
declare(strict_types = 1);
namespace App\Kafka;
use RdKafka;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@srigi
srigi / Base62.php
Created June 29, 2017 11:50
UUID (hex) to base62 and vice-versa
<?php
class Base62
{
const BASE_OCT = 8;
const BASE_DEC = 10;
const BASE_HEX = 16;
const BASE_62 = 62;
@srigi
srigi / gist:f81ce80d5c5c8f815e40
Created June 7, 2014 19:15
cloc statistics by commit
# !/bin/bash
startCommit=$2
initialCommit=`git rev-parse HEAD` # commit of the repository before we start the work
file='cloc-stats.csv'
# use sed to remove duplicate lines with commit ID, git-rev-list not fully accepting my format, arrrgh
if [[ $1 = "--help" || $1 = "-h" ]]; then
echo "Generate 'cloc per commit' stats from a GIT repository by following the parent links from the given commit."
@srigi
srigi / gist:1565135
Created January 5, 2012 12:52
10 New Year’s Resolutions Every Web Developer Should Make
10 New Year’s Resolutions Every Web Developer Should Make
=========================================================
1 - Learn a New Language, Framework or Methodology
--------------------------------------------------
We must continue learning about the latest technologies.
2 - Get Better At What You Know
--------------------------------
Set aside some time to also focus on existing languages and software.