Skip to content

Instantly share code, notes, and snippets.

View jnicholls's full-sized avatar

Jarred Nicholls jnicholls

  • Onda AI
  • Frederick, Maryland
View GitHub Profile
@jnicholls
jnicholls / bincode_stream.rs
Created September 11, 2019 12:35
A message stream example, using an underlying bincode bi-directional stream, which in turn uses tokio-serde under that.
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use bincode::Error;
use bytes::{Bytes, BytesMut};
use futures::{Sink, Stream, TryStream};
use pin_utils::unsafe_pinned;
use serde::{Deserialize, Serialize};
use tokio_serde::{Deserializer, FramedRead, FramedWrite, Serializer};
struct Device {
pub data: u32
}
impl Device {
pub fn new() -> Self { Device { data: 0 } }
pub fn async(&mut self) -> BoxFuture<(), ()> {
async_fn().and_then(|result| {
self.data = result;
```Compiling syntex v0.35.0
Compiling quasi v0.12.0
Compiling aster v0.18.0
Compiling quasi_codegen v0.12.0
Compiling serde_codegen v0.7.10 (https://github.com/serde-rs/serde?rev=8a09f05644ad286e5a18c714ec1af58ed90d1d8b#8a09f056)
error[E0463]: can't find crate for `syntex`
--> /home/vagrant/.multirust/toolchains/stable/cargo/git/checkouts/serde-1cbd136c2e06ab68/8a09f05644ad286e5a18c714ec1af58ed90d1d8b/serde_codegen/build.rs:3:5
|
3 | extern crate syntex;
| ^^^^^^^^^^^^^^^^^^^^ can't find crate
[replace]
"serde_codegen:0.7.10" = { git = "https://github.com/serde-rs/serde", rev = "8a09f05644ad286e5a18c714ec1af58ed90d1d8b" }
SemaphoreSlim signal = new SemaphoreSlim(0, 1);
// set signal in event
signal.Release();
// wait for signal somewhere else
await signal.WaitAsync();
How Do Court Reporters Keep Straight Faces?
These are from a book called Disorder in the Courts and are things people actually said in court, word for word, taken down and published by court reporters that had the torment of staying calm while the exchanges were taking place.
ATTORNEY: What was the first thing your husband said to you that morning?
WITNESS: He said, 'Where am I, Cathy?'
ATTORNEY: And why did that upset you?
WITNESS: My name is Susan!
_______________________________
ATTORNEY: What gear were you in at the moment of the impact?
(void)windowDidResize:(NSNotification*)notification {
if (!shell_->window_state->ignore_changes) {
NSWindow* window = [notification object];
shell_->window_state->last_frame = window.frame;
if (shell_->window_state->state != Ion::IonUI::Window::STATE_HIDDEN) {
if (window.isZoomed && shell_->window_state->type == Ion::IonUI::Window::TYPE_NORMAL)
shell_->window_state->state = Ion::IonUI::Window::STATE_MAXIMIZED;
else
shell_->window_state->state = Ion::IonUI::Window::STATE_NORMAL;
filters: [
["JSON Files", "*.json"],
["All Files", "*.*"]
]
// or
filters: [{
@jnicholls
jnicholls / gist:2400503
Created April 16, 2012 18:22
JSON.stringify Store Records
JSON.stringify(Ext.Array.map(store1.getRange(), function(o) { return o.data; }), null, ' ');
for x in 0..10 {
let promise = Promise::<u32,&str>::new(move || {
match x {
0 => Err("Division by zero"),
_ => Ok(x * 2)
}
}).success(move |res| {
assert_eq!(res, x * 2);
Ok(res * 2)
}).success(|res| {