Skip to content

Instantly share code, notes, and snippets.

View rozgo's full-sized avatar

Alex Rozgo rozgo

View GitHub Profile
// [snippet: Async socket server using F# async computations.]
open System
open System.IO
open System.Net
open System.Net.Sockets
open System.Threading
type Socket with
member socket.AsyncAccept() = Async.FromBeginEnd(socket.BeginAccept, socket.EndAccept)
@rozgo
rozgo / gist:2db80c908cbe085d82b3
Created December 2, 2014 10:26
Async.AwaitObservable
#nowarn "40"
type Microsoft.FSharp.Control.Async with
static member AwaitObservable (evt : IObservable<'a>) =
Async.FromContinuations (fun (cont, econt, ccont) ->
let rec callback value =
sub.Dispose ()
cont value
and sub : IDisposable = evt.Subscribe callback
())
module Signal
open System
type Function =
| Line
| Sine
| Square
| Triangle
| Sawtooth
@rozgo
rozgo / gist:36bfe52f9548b273e9b8
Last active August 29, 2015 14:11
Render Monad WIP
set drawcall (0)
-set shader:Unified (1)
--set color:red (2)
---set shape:box (3)
---unset shape:box (3)
---set drawcall (4)
----set attrib (5)
----unset attrib (5)
---unset drawcall (4)
---set uniform (6)
@rozgo
rozgo / gist:a75a7c726bdd29022056
Created December 17, 2014 23:20
LZMA Compression Settings
LZMA Options:
level
Description: The compression level.
Range: [0;9].
Default: 5.
dictSize
Description: The dictionary size.
@rozgo
rozgo / gist:f5c41d2a29399d0c3d52
Created April 29, 2015 15:51
F# PCL iOS Xamarin
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{F2A71F9B-5D33-465A-A702-920D77279786};{4925A630-B079-445D-BCD4-3A9C94FE9307}</ProjectTypeGuids>
<!-- <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{380F0F87-E153-4FCF-A19F-75E1006BB24C}</ProjectTypeGuids> -->
<!-- <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> -->
<!-- <ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids> -->
<ProjectGuid>{14980659-6907-4542-95C4-054D54680FCA}</ProjectGuid>
@rozgo
rozgo / genetic.py
Last active February 9, 2016 20:40
small python script that evolves an equation towards a solution
# author : Alex Rozgo
# date : Sun Jun 6 2004
# copyright : DoWhatEverYouWantWithIt LICENSE
# email : [email protected]
#
# This is a simple demostration of genetic algorithms.
# Given these digits: '0,1,2,3,4,5,6,7,8,9' the algorithm
# must combine them with these operators '+,-,*,/' and
# find an equation that can evaluate to a given target.
# I'll be using binary encoded genes to represent
@rozgo
rozgo / tmux.cheat
Created May 18, 2017 16:44 — forked from afair/tmux.cheat
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &
@rozgo
rozgo / varint.rs
Last active June 7, 2017 07:50
Variable-length integer implementation in Rust
use std::io::{self, Result};
/// let mut rdr = Cursor::new(buf);
/// let num = rdr.read_varint().unwrap();
pub trait VarintReader: io::Read {
fn read_varint(&mut self) -> Result<u64> {
fn decode<F>(i : u64, mut next : F) -> u64
@rozgo
rozgo / mumble_say.rs
Created October 16, 2017 16:46
snippet of code to process stream of raw PCM audio and encode for opus broadcast
pub fn say<'a>(vox_out_rx: futures::sync::mpsc::Receiver<Vec<u8>>,
udp_tx: futures::sync::mpsc::Sender<Vec<u8>>,
crypt_state: Arc<Mutex<ocbaes128::CryptState>>)
-> impl Future<Item = (), Error = Error> + 'a {
// Hz * channel * ms / 1000
let sample_channels: u32 = 1;
let sample_rate: u32 = 16000;
let sample_ms: u32 = 10;
let sample_size: u32 = sample_rate * sample_channels * sample_ms / 1000;