Skip to content

Instantly share code, notes, and snippets.

View urandom's full-sized avatar

Viktor Kojouharov urandom

View GitHub Profile
@urandom
urandom / init.lua
Last active August 8, 2022 19:06
init.lua
-- Install paq
local execute = vim.api.nvim_command
local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
execute('!git clone --depth 1 https://github.com/savq/paq-nvim.git ' .. install_path)
end
require('paq') {
@urandom
urandom / NULL-safety.md
Last active March 31, 2021 13:44
null safety

Go supports nil values for certain classes of types, namely: pointers, functions, interfaces, maps, slices and channels. Nil values of these types indicate an absence of value, and vary in usability. Slices and channels are quite usable as nil values, maps less so. For pointers, interfaces and functions, besides indicating an absence, the nil value has little other usability and usually results in a panic if not checked beforehand.

And while the nil value has usability, sometimes a developer want one of the abovementioned type classes to always be non-nil. Unfortunately, Go currently does not provide an expression for such a use case.

The document explores two possible ways to provide such an expressibility, by investigating various languages that have either been designed from the ground up to support such constructs, or they have been added after the fact.

Optional-based

Some languages allow the developer to speficy whether a value is there or not by means of an Optional or similar object. Such an o

@urandom
urandom / steam-225540.log
Created July 26, 2020 19:27
Just Cause 3 steamos
Linux steamos 4.19.0-0.steamos2.3-amd64 #1 SMP Debian 4.19.45-1~steamos2.1 (2019-05-24) x86_64 GNU/Linux
Zotac Nen
4.6.0 Nvidia 415.27
[ DEBUG ] 2020-02-23T20:18:33Z+0100 ] /usr/share/nvim/runtime/lua/vim/lsp.lua:607 ] "on_lines" 1 176 40 40 41 0 0 0 { "\t" }
[ DEBUG ] 2020-02-23T20:18:33Z+0100 ] /usr/share/nvim/runtime/lua/vim/lsp.lua:607 ] "on_lines" 1 177 40 41 41 2 2 2 { "\t\t" }
[ DEBUG ] 2020-02-23T20:18:33Z+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:269 ] "rpc.notify" "textDocument/didChange" { contentChanges = { { text = 'package storage\n\nimport (\n\t"context"\n\t"reflect"\n\t"sort"\n\t"testing"\n\n\t"github.com/globusdigital/feature-toggles/toggle"\n\t"github.com/stretchr/testify/assert"\n)\n\nvar initialData = []toggle.Flag{\n\t{Name: "n1", ServiceName: "svc1", RawValue: "t", Value: true},\n\t{Name: "n2", ServiceName: "svc1", RawValue: "0"},\n\t{Name: "n3", ServiceName: "svc2", RawValue: "1", Value: true},\n\t{Name: "n4", ServiceName: "", RawValue: "some data"},\n\t{Name: "n5", ServiceName: "", RawValue: "y", Value: true},\n}\n\nfunc TestMem_Get(t *testing.T) {\n\ttype args struct {\n\t\tctx context.Context\
@urandom
urandom / example.go
Last active August 6, 2019 19:33
Bounded pipelines with generics
package pipes_test
import (
"context"
"crypto/md5"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@urandom
urandom / README.md
Last active September 14, 2018 07:55
Reducing the special casing around the new error design draft

Reducing the special casing around the new error design draft

The error design draft is a good step in simplifying both the reading and writing of variety of code. I was even surprised that it efficiently allows readable handling of errors within http handlers:

func ListHandler(r Repo) {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    handler err {
      http.Error(w, http.StatusText(500), 500) 
 }
@urandom
urandom / change-wallpaper
Last active May 26, 2019 19:10
Change gnome3's wallpaper from a random one in a directory
#!/usr/bin/python3
import os
import random
import subprocess
import sys
import urllib.request, urllib.parse, urllib.error
from os.path import isfile, join
@urandom
urandom / MyActivity.java
Last active May 25, 2017 08:57
Retained view model skeleton for using with data binding on android. Useful when you have rxjava stuff in your view model and you want it to survive configuration changes.
public class MyActivity extends AppCompatActivity {
private MyViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
viewModel = RetainedFragment.getViewModel(
getFragmentManager(),
MyViewModel.class.getName(),
@urandom
urandom / Activity.java
Last active April 22, 2016 06:37
Taking control of android's drawer toggle
// Where you setup the toolbar
toolbarDelegate = new ToolbarCompatDelegate(toolbar);
slider = new DrawerArrowDrawableToggle(toolbarDelegate.getActionBarThemedContext());
// DrawerLayout.DrawerListener implementation
@Override public void onDrawerSlide(View drawerView, float slideOffset) {
slider.setPosition(Math.min(1f, Math.max(0, slideOffset)));
}
@urandom
urandom / Adapter.java
Created November 13, 2015 09:16
RecyclerView Grid adapter with header support and proper merging of items
package com.example.test.adapter;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.transitionseverywhere.TransitionManager;