Skip to content

Instantly share code, notes, and snippets.

@DrMetallius
DrMetallius / Main.kt
Last active November 9, 2020 12:01
Exceptions in coroutines
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import kotlinx.coroutines.runBlocking
@DrMetallius
DrMetallius / PC-Programmer.json
Created April 22, 2020 17:15
Karabiner configuration for convenient Mac programming
{
"title": "PC Programmer",
"rules": [
{
"description": "Change grave accent (`) to ё in Russian layout",
"manipulators": [
{
"conditions": [
{
"type": "input_source_if",
@DrMetallius
DrMetallius / Main.kt
Created August 31, 2019 20:41
Element ordering in Rx operators
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
import kotlin.random.Random
fun main() {
/*
* Output:
*
* 0
@DrMetallius
DrMetallius / ColorPickerActivity.kt
Created August 31, 2019 20:40
LivingCells color picker activity
package com.malcolmsoft.livingcells
import android.app.Activity
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.SweepGradient
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
@DrMetallius
DrMetallius / listsort.cpp
Created August 31, 2019 20:37
Linked list sorting
#include <iostream>
struct Entry {
char name[20];
unsigned int price;
Entry *nextEntry;
};
Entry *readAlphabeticList();
Entry *sortByPrice(Entry *list);
@DrMetallius
DrMetallius / snippet.rs
Created August 31, 2019 20:36
COM in Rust
use winapi::shared::ntdef::LPCWSTR;
use winapi::um::winuser::{BS_DEFPUSHBUTTON, SW_SHOW, WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_OVERLAPPEDWINDOW, WNDCLASSW};
use winapi::shared::minwindef::{HINSTANCE, UINT, WPARAM, LPARAM, LPVOID, DWORD};
use winapi::shared::windef::{POINT, HBRUSH, HMENU, HWND};
use winapi::um::winuser;
use winapi::um::winuser::{BS_TEXT, GetWindowLongW};
use winapi::um::libloaderapi::GetModuleHandleW;
use winapi::shared::minwindef::LRESULT;
use winapi::shared::wtypesbase::CLSCTX_INPROC_SERVER;
use std::ffi::{OsStr, OsString};
@DrMetallius
DrMetallius / api_model.go
Created August 31, 2019 20:35
Backup Authentication
package main
type IdentityProviderLocation struct {
ServerUrl string `json:"server_url"`
Id int `json:"id"`
Login string `json:"login"`
}
type OpenIdentityProviderSessionResponse struct {
AccessToken string `json:"access_token"`
@DrMetallius
DrMetallius / main.rs
Created August 31, 2019 20:34
S-expression parser
use std::io;
use std::io::{Bytes, Read, Error, ErrorKind};
use std::str;
use std::fmt;
use std::fmt::{Display, Write};
use std::str::FromStr;
fn main() {
let result = ExpressionReader::read(io::stdin()).unwrap();
println!("Result: {:?}", result);
@DrMetallius
DrMetallius / main.rs
Created August 31, 2019 20:32
Rock Paper Scissors
extern crate rand;
use std::io;
use rand::os::OsRng;
use rand::Rng;
fn main() {
let mut choice_maker = ChoiceMaker::new();
let stdin = io::stdin();
@DrMetallius
DrMetallius / main.rs
Created August 31, 2019 20:32
FTP in Rust
extern crate ftp;
use ftp::FtpStream;
use std::fs::File;
use std::error::Error;
use std::io;
fn main() {
let result = download("example.com:21", "anonymous", "anonymous", ".", "Test.txt");
match result {