Skip to content

Instantly share code, notes, and snippets.

import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
private suspend fun <T> getChunk(channel: Channel<T>, maxChunkSize: Int): List<T> {
// suspend until there's an element in the buffer
@AWinterman
AWinterman / .vimrc
Created June 18, 2019 22:31
June 2019 my vimrc
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-easy-align'
Plug 'https://github.com/sjl/gundo.vim.git'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
Plug 'https://github.com/lifepillar/pgsql.vim.git'
@AWinterman
AWinterman / .vimrc
Created June 18, 2019 22:31
June 2019 my vimrc
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-easy-align'
Plug 'https://github.com/sjl/gundo.vim.git'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
Plug 'https://github.com/lifepillar/pgsql.vim.git'
@AWinterman
AWinterman / everything-is-terrible.md
Created January 30, 2019 01:26
Everything on the internet about using angular and django is terrible

Everyting on the internet about configuring angular and django to play nice together is garbage.

  1. Refer to the angular docs over any tutorial out there because everytyhing else is garbage.
  2. If anything mentions webpack, stop reading it, unless what you actually want is to learn about webpack.
  3. If anybody mentions turning off CORS or CSRF protections, screaming inside is encouraged, but if you let it you your non-technical coworkers will look at you funny.

What you need to know is the following. Angular's HTTP module will add the CSRF token if it was available. You just have to coordinate how your app will send it up with where angular looks for it. https://angular.io/guide/http#security-xsrf-protection

If you want to get the CSRF token from the webframework, (django in my case), you have to serve the front end from django. This is easy enough if you add the following to the JSON object at projects.your-dumb-project.architect.build.options:

@AWinterman
AWinterman / Datagate.py
Created May 30, 2012 21:01
Script to convert from csv to sqlite3
import csv
import sqlite3 as lite
import subprocess
from itertools import chain
from time import time
import sys
#import logging
#logging.basicConfig(level=logging.DEBUG)
#
@AWinterman
AWinterman / main.js
Created December 3, 2013 05:41
Asynchronous + event emitter
E = require('events').EventEmitter
function fn(ready, eventArg) {
var result = // do some async stuff with to compute result
if(/* error encountered */) {
ready(new Error)
}
ready(null, result)
}
@AWinterman
AWinterman / varsort
Created August 6, 2013 22:02
varsort.sh
#!/usr/bin/env sh
# varsort: reorder lines according to length.
cat $0 | awk '{print length($0), $0}' | sort -n | tac | cut -d' ' -f2-
suite("name of test suite", function(require) {
var MapPicker = require('../../require/some/module')
test('test something', function() {
assert.equal(some, things)
})
})
@AWinterman
AWinterman / circle.r
Created July 3, 2012 16:05
bar chart in polar coordinates
G = ggplot(data = frame
, aes(x = 10
, label = New.HIV.Infections.due.to.MTCT
, y = sqrt(New.HIV.Infections.due.to.MTCT)
, fill = contribution.to.global.MTCT.burden))+
geom_bar( stat= "identity", position = "identity")
#This will make a stacked bar chart with one column, with colors determined by the contribution to the global burden.
#I'm going to map x to angle and y to radius (hence the square root above)
G = G+theme_bw()+opts(axis.text.x = theme_blank(), legend.position = "bottom", axis.ticks = theme_blank() )+coord_polar(theta = "x")