Skip to content

Instantly share code, notes, and snippets.

@alicemaz
alicemaz / nginx.conf
Created January 4, 2016 06:25
my nginx setup
user www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;
let bytes = input.as_bytes();
let mut raw = Vec::<u8>::with_capacity(input.len());
for (offset, codepoint) in input.char_indices() {
let c = codepoint as u32;
if (c > 0x40 && c < 0x5b) || (c > 0x60 && c < 0x7b) ||
(c > 0x29 && c < 0x3a) || c == 0x2b || c == 0x2f {
raw.push(bytes[offset]);
} else if codepoint.is_whitespace() || c == 0x3d {
let mut opts = HashMap::new();
opts.insert("screen_name", "someone");
let opts = opts;
let json = twitter.get("users/show", &opts);
println!("{}", json.pretty());
let obj = json.as_object().unwrap();
let sn = obj.get("screen_name").unwrap().as_string().unwrap();
let mut key = String::new();
let mut sec = String::new();
let mut tok = String::new();
let mut tok_sec = String::new();
for (var, val) in env::vars() {
match var.as_ref() {
"TWITTER_KEY" => key = val,
"TWITTER_SECRET" => sec = val,
"TWITTER_TOKEN" => tok = val,
@alicemaz
alicemaz / hash.rs
Last active November 28, 2015 02:35
//this works
fn hash(data: &[u8], key: &[u8]) {
let mut hmac = Hmac::new(Sha1::new(), key);
hmac.input(data);
let signature = &hmac.result().code().to_base64(B64_STD);
println!("sig:\n{}", signature);
}
//this does not work (compiler error in next file)
mod twot {
pub struct Config<'a> {
key: &'a str,
secret: &'a str,
token: &'a str,
token_secret: &'a str
}
impl<'a> Config<'a> {
pub fn new(key: &'a str, sec: &'a str, tok: &'a str, tok_sec: &'a str) -> Config<'a> {
@alicemaz
alicemaz / stream.js
Last active October 3, 2015 07:59
minimum twitter stream
"use strict";
var Twit = require("twit");
var T = new Twit({
consumer_key: "",
consumer_secret: "",
access_token: "",
access_token_secret: ""
});
var pl = function(file) {
var img = new Image();
img.src = "img/"+file+".jpg";
return img;
};
var imgs = {
readers: pl("lov0"),
circle: pl("lov1"),
blanket: pl("lov2"),
@alicemaz
alicemaz / tvid.js
Created August 3, 2015 03:35
twine video
window.vidloader = function() {
var vid = document.createElement("video");
vid.src = "vid.ogv";
vid.preload = "auto";
return "";
};
@alicemaz
alicemaz / alice.erl
Created July 22, 2015 15:04
original xor thing
-module(alice).
-export([decrypt_xor/1]).
decrypt_xor(Text) ->
Strings = lists:map(fun(N) ->
{N, char_distro([X bxor N || X <- Text])} end, lists:seq(0,255)),
[{Key,_}|_] = lists:reverse(lists:keysort(2, Strings)),
[X bxor Key || X <- Text].
char_distro(Text) ->