Skip to content

Instantly share code, notes, and snippets.

@yuce
yuce / erlang-wx-requirements.sh
Last active April 26, 2016 18:04
Requirements for Erlang + Wx on Ubuntu
sudo apt-get install libssl-dev libwxgtk3-dev freeglut3dev
sudo apt-get install libxcb1-dev libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev \
libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-xinerama0-dev libpango1.0-dev \
libxcursor-dev libxcb-cursor-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev
BinAccessToken = list_to_binary(httpc_uri:encode(AccessToken)),
Body = <<"--", Boundary/binary, ?CRLF,
"Content-Disposition: form-data; name=\"access_token\"", ?CRLF,
?CRLF,
BinAccessToken,?CRLF,
--", Boundary/binary, ?CRLF,
"Content-Disposition: form-data; name=\"", BinFieldName/binary,
"\"; filename=\"", BinFileName/binary, "\"", ?CRLF,
"Content-Type: application/octet-stream", ?CRLF,
?CRLF,
#! /usr/bin/env escript
%% 2014, @tklx
-define(SERVER_URL, "http://127.0.0.1:5000/").
-define(CRLF, "\r\n").
main([]) ->
io:format("Usage: upload file1 file2...~n");
main(Args) ->
@yuce
yuce / selenium-test.py
Created May 3, 2014 21:19
Sample selenium test
import time
import unittest
from selenium import selenium
# Select Firefox as the browser
# (Note that this is not Google's Chrome)
BROWSER = '*chrome'
SITE_URL = 'http://en.wikipedia.org'
class WikipediaSeleniumTest(unittest.TestCase):
@yuce
yuce / nearestneighbor-bad.py
Created May 3, 2014 20:50
Nearest neighbor (bad)
class Nearestneighbor:
def __init__(self, dists):
self.__dists = dists
self.dimension = dists.shape[0]
def construct(self, startcity = None):
if startcity is None:
self.startcity = rnd.randint(self.dimension)
else: self.startcity = startcity
@yuce
yuce / nearestneighbor.py
Created May 3, 2014 20:50
Nearest neighbor
def nearestneighbor(size, dists):
tour = [0]*size
candy = [True]*size
candy[0] = False
for i in range(1, size):
prev = tour[i - 1]
tour[i] = min([(dists[prev][c], c)
for c in range(size) if candy[c] and c != prev])[1]
candy[tour[i]] = False
@yuce
yuce / infixoop.mar
Created May 3, 2014 20:44
OOP infix to postfix (Marvin)
# infixoop.mar | Converts an infix expression into postfix
# This implementation uses the object data as a hash-table
# for operator precedence.
"listop forth dequeop" use
@@Infix
@new # define the hash-table for operator precedence
FALSE ^++ ^+- ^-+ ^-- ^*+ ^*- ^** ^*/ ^/+ ^/- ^/* ://
@yuce
yuce / infix.mar
Created May 3, 2014 20:41
Convert an infix expression to postfix (Marvin)
# infix.mar | Converts an infix expression into postfix
# This implementation uses the global variable space as a hash-table
# for operator precedence.
"listop forth dequeop" use
@|> globs & pushfrom ;
@string dfront NONE =
@yuce
yuce / link-checker.go
Created May 3, 2014 20:38
Go link checker