Skip to content

Instantly share code, notes, and snippets.

doug:rust-libs doug$ cat junk.rs
#![crate_id = "junk#0.1"]
use std::libc::c_int;
#[no_mangle]
pub extern fn dothing(a: c_int, b:c_int) -> c_int {
return a + b;
}
@trissylegs
trissylegs / ipc.c
Created June 25, 2015 10:22
Demonstration of shared memory using C and Rust
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
@durka
durka / countmacro.rs
Last active April 13, 2016 23:50 — forked from anonymous/playground.rs
Rust macros: counting with an accumulator
// cargo-deps: lazy_static
#[macro_use] extern crate lazy_static;
macro_rules! declare_array {
// INTERNAL
// last element (proceed to output)
(@parse $size:expr, ($val:expr) -> [$($accs:expr),*] $thru:tt) => {
declare_array!(@output $size + 1usize, [$($accs,)* $val] $thru);
anonymous
anonymous / playground.rs
Created October 10, 2016 10:10
Shared via Rust Playground
let request_url = "https://some.api/path.json"
let client = Client::new();
let mut res = client.get(&request_url).send().unwrap();
assert_eq!(res.status, hyper::Ok);
println!("Reading body..");
let mut res_body = String::new();
let result = res.read_to_string(&mut res_body).unwrap();
println!("Done");
@jijojv
jijojv / gist:8139217
Last active January 16, 2017 03:08 — forked from karlseguin/gist:1876859
sublime scp to remote on save
#variation of http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ that adds creating new folders remotely.
import sublime_plugin, os
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
remote = { "/Users/jijo/work/project": ["/usr/bin/scp", None, "user@server", "~/project/", None] }
for dirname, target in remote.iteritems():
if view.file_name().startswith( dirname ):
anonymous
anonymous / playground.rs
Created May 26, 2017 07:46
Shared via Rust Playground
#[post("/tablet-reg-mode-status")]
fn reg_mode_status() -> Res<bool> {
ok(REGISTER_MODE.load(Ordering::Relaxed))
}
#[post("/tablet-reg-mode-toggle")]
fn reg_mode_toggle(_me: Admin) -> Res<bool> {
for {
let old = REGISTER_MODE.load(Ordering::SeqCst);
@kashif
kashif / es.py
Last active June 5, 2017 12:07
Initial implementation of Evolution Strategies
import numpy as np
import gym
from gym.spaces import Discrete, Box
from gym.wrappers import Monitor
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
# ================================================================
# Policies
anonymous
anonymous / index.html
Created June 18, 2017 21:39
paper-tabs with iron-pages
<head>
<!-- <base href="https://polygit.org/polymer+1.7.0/components/"> -->
<base href="https://cdn.rawgit.com/download/polymer-cdn/1.7.0/lib/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-tabs/paper-tab.html">
<link rel="import" href="iron-pages/iron-pages.html">
</head>
anonymous
anonymous / playground.rs
Created June 19, 2017 06:34
Shared via Rust Playground
use std::cell::UnsafeCell;
use std::ops::*;
use std::marker::PhantomData;
pub struct DefaultTag {}
pub struct SyncCell<'cc, T> {
unsafe_cell: UnsafeCell<T>,
phantom_borrow_creator: PhantomData<&'cc ()>,
}
anonymous
anonymous / playground.rs
Created September 7, 2017 22:31
Rust code shared from the playground
extern crate clap;
use clap::{App,Arg};
fn main() {
let m = App::new("My Program")
.arg(
Arg::with_name("demo").short("d")
)
.arg(
Arg::with_name("rest")