Skip to content

Instantly share code, notes, and snippets.

View umurgdk's full-sized avatar

Umur Gedik umurgdk

View GitHub Profile
use std::sync::{Arc, Mutex};
use std::sync::mpsc::SyncSender;
use std::marker::PhantomData;
use iron::prelude::*;
use iron::{BeforeMiddleware, typemap, Request};
use workers::MetricWriterCommand;
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Theme {
/// Colors used to highlight nicks
pub nick_colors: [u8; 13],
pub clear: Style,
pub user_msg: Style,
pub err_msg: Style,
pub topic: Style,
pub cursor: Style,
# servers to auto connect
servers:
- addr: irc.mozilla.org
port: 6667
hostname: freenode
colors:
user_msg:
fg: black
bg: default
#[macro_export]
macro_rules! retry {
( @create_multiple_runner $timeout:expr, $started_at:expr, $( $name:ident: $type:ty => $block:expr ),+ ) => {
{
let resources = Resources {
$(
$name: retry!(@create_runner $timeout, $started_at, $block)
),+
};
pub fn remove_child(&mut self, child: &Box<View>) -> Option<Box<View>>
{
match self.children.iter().position(|v| ptr::eq(v, child)) {
Some(index) => Some(self.children.remove(index)),
None => None
}
}
@umurgdk
umurgdk / body_parser.rs
Created June 18, 2017 02:46
Body parser memory leak!
use std::collections::BTreeMap;
use iron::prelude::*;
use iron::{BeforeMiddleware, typemap};
use params::Params;
use serde_json;
use models::Payload;
extern crate rusqlite;
extern crate app_dirs;
extern crate libc;
use rusqlite::{Connection, Statement};
use app_dirs::*;
use std::fs::{File};
use std::io::prelude::*;
use std::sync::mpsc::channel;
use std::sync::mpsc::{Sender, Receiver};
import requests
instance_url = 'https://mastodon.cloud'
api_base_url = instance_url + '/api/v1'
# final url is https://mastodon.cloud/api/v1/instance
def get_instance_info():
req = requests.get(api_base_url + '/instance')
return req.json()
CREATE TABLE "Measures" (
key text,
created_at timestamp,
updated_at timestamp,
version = timestamp,
start_date text,
end_date text,
unit text,
target varint,
target_type text,
def list() = {
println(s"-------------------Domain ID: $domainId")
val dashboardKeys = for {
row <- session.execute(GET_DASHBOARD_IDS, domainId.toString).all.asScala
dashboardId <- Option(row.getString("dashboardId"))
key = s"$domainId-$dashboardId"
} yield key
println("---------------------Dashboard keys:")
println(dashboardKeys.toList)