Skip to content

Instantly share code, notes, and snippets.

@aleics
aleics / Calling methods of a class in Javascript
Last active August 29, 2015 14:22
Sending values to methods of one class (Javascript):
<!-- We can call the function using the onclick function on the html -->
<input type="image" id="sayhi_input" onclick="pop.create('Say hi!')">
<script>
//Declaration of the Class "Popup"
function Popup() {
}
Popup.prototype = {
constructor: Popup, //Construct
@aleics
aleics / Local active directory (add, edit, delete)
Created May 30, 2015 15:01
How to add, edit and delete active directory users of the local space in C#
//Create a new user on the local active directory
public bool add_user(string user_name, string user_password) {
try {
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add(user_name, "user");
NewUser.Invoke("SetPassword", new object[] { password_password });
NewUser.Invoke("Put", new object[] { "Description", user_name });
NewUser.CommitChanges();
@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
// 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"
)
router.HandleFunc(`/configfile/{filename:[-\w./_0-9]+}`, getConfigfileHandler).Methods("GET")
@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)
})
}
#![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 / insensitive_sorting.js
Created March 7, 2017 09:01
Lodash insensitive sorting
var selection = _.sortBy(elements, [element => _.lowerCase(element.a),
element => _.lowerCase(element.b)])
@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 / 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