Skip to content

Instantly share code, notes, and snippets.

@aleics
aleics / result.ts
Created February 4, 2021 17:51
Rust Result in Typescript 🦀
interface Cases<O, T, E, R> {
ok: (value: O) => T;
err: (value: E) => R;
}
export abstract class Result<O, E> {
public abstract isOk(): boolean;
@aleics
aleics / clone_stream.rs
Created January 8, 2021 06:55
Clone streams by using Bus
use bus::{Bus, BusReader};
use futures::task::{Context, Poll};
use futures::Stream;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
/// `SourceInner` contains the reference to the Bus. `SourceInner` is available to the
/// `Source` instance, as well as its connected `SourceNode`. The `inner` needs to be wrapped
/// around a `Mutex` so that it's possible to include new receivers, and around a `Arc` so that
/// the instance is cloneable, potentially from multiple threads.
@aleics
aleics / db.rs
Created July 18, 2018 11:11
Diesel connection with the Rocket Framework
use r2d2::{Pool, PooledConnection, Error};
use r2d2_diesel::ConnectionManager;
use diesel::PgConnection;
use rocket::http::Status;
use rocket::{Request, State, Outcome};
use rocket::request::{self, FromRequest};
/// DatabaseHandler handles a single connection to the database
@aleics
aleics / docker-compose.yml
Last active July 17, 2018 20:38
Files used for the creation of a GraphQL endpoint using Rocket
version: '2'
services:
rustql:
image: rustql
restart: always
container_name: rustql
networks:
rustql-network:
ipv4_address: 172.11.0.2
@aleics
aleics / insensitive_sorting.js
Created March 7, 2017 09:01
Lodash insensitive sorting
var selection = _.sortBy(elements, [element => _.lowerCase(element.a),
element => _.lowerCase(element.b)])
#![allow(dead_code)]
use std::f32::INFINITY;
use std::sync::{Arc};
use std::thread;
use std::sync::mpsc::channel;
struct Store {
name: String,
items: Vec<Item>,
}
@aleics
aleics / Rust : reading file
Created August 22, 2016 08:46
How to properly and efficiently read a file in Rust
fn file_to_bytes(path: &Path) -> Result<Vec<u8>, std::io::Error> {
File::open(path).and_then(|mut file| {
let mut bytes = Vec::new();
try!(file.read_to_end(&mut bytes));
Ok(bytes)
})
}
router.HandleFunc(`/configfile/{filename:[-\w./_0-9]+}`, getConfigfileHandler).Methods("GET")
// gist saved for future use
// practice code of the decorator pattern for http requests
// extracted from the talk of Tomas Senart (http://bit.ly/22tUcl4)
package main
import (
"log"
"net/http"
"os"
)
@aleics
aleics / nginx_onpublish_soap.txt
Last active October 28, 2015 08:42
Nginx on_publish + SOAP Request (C#)
It is possible with the nginx to make a request when the nginx detect an input stream on our application
(more info: https://github.com/arut/nginx-rtmp-module/wiki/Directives).
As you can see on the wiki of the nginx rtmp module, different triggers are defined (on_play, on_publish,
etc.). To detect a new stream coming in our nginx it will be an "on_publish" event called.
With this method it will be sended diferent parameters too. This parameters will be sended as a form post
data.
The parameters sended on the form post are:
- clientid - tcurl