Skip to content

Instantly share code, notes, and snippets.

@se1983
se1983 / .py
Last active November 14, 2015 11:12
Generate a list of radiostations from http://wiki.ubuntuusers.de/internetradio/stationen#Radiosender-Deutschland and save it in json for a synology DSM
from __future__ import unicode_literals
from bs4 import BeautifulSoup
from urllib import urlretrieve
import re
import json
import mechanize
class Browser(mechanize.Browser):
''' Browser
import numpy as np
import pandas as pd
from PIL import Image
from keras import backend as K
from keras.preprocessing.image import load_img, img_to_array
from keras.applications import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.layers import Input
from scipy.optimize import fmin_l_bfgs_b
import time
@se1983
se1983 / app.py
Last active January 30, 2018 15:56
Using flask to deliver plt
from io import BytesIO
from flask import Flask, make_response, render_template
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from BA_argo_playground.plot_image import create_plot
app = Flask(__name__, template_folder="/home/sebsch/Dokumente/Uni-Workdir/Bachelorarbeit/BA_argo_playground/templates")
@app.route("/simple.png")
def simple():
@se1983
se1983 / main.rs
Last active January 26, 2020 23:56
request and marshal reddit data with rust
use ureq;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::error::Error;
#[derive(Serialize, Deserialize)]
struct Data {
title: String,
author: String,
subreddit: String,
@se1983
se1983 / serde_deserialize_constructor.rs
Last active October 31, 2022 11:25
rust constructors creating structs
use serde::{Deserialize, Serialize};
pub trait SerdeDeserializeObject {
fn new<'de>(data: &'de str) -> Self
where
Self: Deserialize<'de>,
{
let serialized_data: Self = serde_json::from_str(&data).unwrap();
serialized_data
}
@se1983
se1983 / playground.rs
Created March 19, 2020 12:28 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::thread;
use std::time::Duration;
use std::collections::HashMap;
struct Cacher<T> where T: Fn(u32) -> u32{
calculation: T,
values: HashMap<u32, u32>
}
impl<T> Cacher<T> where T: Fn(u32) -> u32 {
@se1983
se1983 / boxed_cacher_part_of_struct.rs
Last active January 3, 2024 12:51
Caching http requests
use ureq;
use std::collections::HashMap;
use std::time::{Instant, Duration};
pub struct Cacher {
call: Box<dyn Fn(&str) -> String>,
data: HashMap<String, (String, Instant)>,
cache_time: Duration,
}
@se1983
se1983 / playground.rs
Last active April 19, 2020 06:39 — forked from rust-play/playground.rs
Channels between two threads
use std::thread;
use std::sync::mpsc;
fn main() {
let (tx, rx) = mpsc::channel();
let h1 = thread::spawn(move || {
let val = String::from("hi");
tx.send(val).unwrap();
});
@se1983
se1983 / log_regex.rs
Created June 30, 2020 17:40
regex loglines with rust
use regex::Regex;
fn main() {
let datetime = r"[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9],[0-9][0-9][0-9]";
let host = r"([^\s]+)";
let service = r"([^\s]+)";
let message = r"(.*)";
let re = Regex::new(&format!("(?P<datetime>({d})) (?P<hostname>({h}))] (?P<service>({s})) (?P<message>({m}))",
d = datetime, h = host, s = service, m = message)).unwrap();
@se1983
se1983 / regextract.rs
Last active July 1, 2020 18:40
Extract fields from logline with regex in rust.
use regex::{Regex, Captures};
use strfmt::strfmt;
use std::collections::HashMap;
fn main() {
#[derive(Debug)]
struct LogSchema{
datetime: String,