ruxoz
ruxoz
Life of ...
136 posts
Nothing
Don't wanna be here? Send us removal request.
ruxoz · 10 years ago
Text
Use Hyper web server in Rust
Ref: http://redd.it/305ih7
Assume you are using Windows and you have just installed Rust. If you want to play with web server in Rust, there are a couple additional steps in order to successfully build Hyper (Rust's most mature web server to date). The steps are following:
Install gcc compiler
I used mingw x64 system. The installer doesn't set PATH env for you so you have to set it yourself.
Install Windows OpenSSL
OpenSSL for Windows can be found at http://slproweb.com/products/Win32OpenSSL.html. I chose x64 v1.0 installer and install with default setting, so the library should be located on C:\OpenSSL-Win64
Set OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR
For the OpenSSL lib to be discovered by Cargo, these two env variables must be set. My setting is following:
set OPENSSL_LIB_DIR=C:\OpenSSL-Win64 set OPENSSL_INCLUDE_DIR=C:\OpenSSL-Win64\include
After complete these steps, you should be able to successfully build a crate that uses hyper crate. If you have failed before trying these steps, try cargo clean and try again :)
0 notes
ruxoz · 10 years ago
Text
In Rust document, FFI seems to be easy and very similar to .Net DllImport.... but in reality it's a different story! My first attempt was to use compiler directive #![link] but it failed from incorrect usage. I later found out there are already Win32 ported in crate.io so instead to research on correct FFI implementation, I've decided to use them and it's still hard to use.
Anyway, after one day of trial & error, I finally managed the "Hello, world!" code to work!
![feature(collections)]
extern crate winapi; extern crate user32;
use std::ptr::{null_mut};
fn w16str(s: &str) -> Vec { let mut w16: Vec = s.utf16_units().collect(); w16.push(0); w16 }
fn main() { unsafe { user32::MessageBoxW( null_mut() , w16str("Hello, world!").as_ptr() , w16str("Test").as_ptr() , 0); } }
user32 crate builds upon winapi crate, which provides Windows basic system types, so chance is you'll have to also use winapi crate in your code.
The Windows API I use for this experiment is MessageBox, which takes 4 parameters; handle to a parent window, message text, header text, and button config. The window handle can be NULL if it's not needed. I've spent hours just to find the way to instantiate NULL pointer and finally found std::ptr::null_mut() >< ... Perhaps I still do not completely understand Interop types needed.
The second pain point I found was string compatibility. Rust's string is UTF32 by default and Windows API uses Wide String, which is UTF16(? if I don't misunderstand). There is a convenient method to convert Rust string to utf16, the function named utf16_units(), but!!! it is unsafe function so it cannot be used in stable version of Rust. The more I learn about Rust the more I'm not sure whether I'm ready to get though all these hardness .... It seems to me that Rust is still immature in FFI area...
After I've installed Nightly build of Rust, the compiler allows me to use the method and then I can easily convert Rust's string to UTF16 as shown in function w16str(). Finally, the FFI MessageBoxW function is unsafe so it must be wrapped in unsafe block, which is fine. I think I may try to create a Windows application with Rust to see more potential issues. Let's see if I have a chance.
0 notes
ruxoz · 11 years ago
Photo
Tumblr media
Routing problem in F#, ported from Haskell -> http://learnyouahaskell.com/functionally-solving-problems
source: https://dl.dropboxusercontent.com/u/12964441/route.fsx
0 notes
ruxoz · 11 years ago
Photo
Tumblr media
F# typeclass workaround, compared to Haskell version @ http://learnyouahaskell.com/functionally-solving-problems
0 notes
ruxoz · 11 years ago
Text
F# and Visual Studio: where IntelliSense fools you.
F# seems to have two way to compile the language. For example, the following code snippet causes an error where "x.RootDirectory" cannot be determined but If you check with intellisense in VS, you should see that all variable's types are already recognized!??
open System.IO open System.Collections.Generic type A() as me = let drives = new List<DriveInfo>() let x = me.SelectedDrive let y = x.RootDirectory // error here member this.SelectedDrive with get() = drives.[0]
So why it cannot be compiled? According to the answer of my question on StackOverflow.com, this.SelectedDrive is not yet recognized by the compiler so it causes error. But this is contrary to the IntelliSense where it reports the type correctly! Apparently, the parser used in Visual Studio's Intellisense is different (and smarter?) than the one used in the compiler itself... funny but the bottom line is don't trust IntelliSense for F# ^^;
0 notes
ruxoz · 11 years ago
Text
ความประหลาดของของ randomness คือ มันดูเหมือนการสุ่มตราบใดที่เรายังไม่เห็นรูปแบบของมัน เช่น 5 3 5 8 9 7 9 3 2 3 8 4 6 ดูเหมือนเป็นเลขสุ่ม แต่ถ้ามองออกจะรู้ว่าตัวต่อไปเป็น 2 เพราะชุดเลขดังกล่าวเป็นส่วนหนึ่งของ Pi
0 notes
ruxoz · 11 years ago
Text
ดูว่าลูกเต๋าถ่วงหรือไม่
บทความเก่า สั้นๆ ใน Math symposium(มั้ง) ว่าด้วย "ทำอย่างไรถึงจะรู้ว่าเต๋าถ่วง"
ideally เต๋า (หรือ random function อะไรก็ตาม)ที่ให้ตัวเลขกระจายสม่ำเสมอ ค่าเฉลี่ยของความน่าจะเป็น จะเท่ากับ (1/n)(sum 1..n) เช่น ลูกเต๋า 6 หน้า (1d6) = (1/6)(1+2+3+4+5+6) = 3.5
คราวนี้เวลาโยนเต๋า สมมติ 50 ครั้ง ที่ต้องทำคือหาความน่าจะเป็น (p) ของแต่ละหน้าเต๋า และคำนวณค่าเฉลี่ยด้วย sum( p * เลขหน้า ) -_-a #ตอนแรกนึกว่าจะอธิบายได้ง่าย ... btw ดูว่ามันใกล้ 3.5 มาก/น้อย
แต่ถ้าได้ 3.5 พอดี ก็ไม่ได้แปลว่าเต๋าไม่ถ่วง (เช่น 6 ออก 25 ครั้ง 1 ออก 25 ครั้ง -- เฉลี่ยได้ 3.5)
คุณคนนี้เลยเสนอการคำนวณหา entropy (ค่าความวุ่นวาย?) โดยสูตรดังกล่าว โดยที่ ถ้าเต๋าถ่วง ค่า h(p) จะเข้าใกล้ 0 ... และ��้าเต๋ากระจายตัวสม่ำเสมอ perfect h(p) จะเป็นค่า maximum ได้แก่ log(e) n --> เมื่อ n เป็นจำนวนหน้าเต๋า (log(e) 6 = 1.79) อย่างน้อยถ้าเต๋าไม่ถ่วง ค่าที่ได้ควรจะใกล้เคียง maximum (ซึ่งแปลว่ามีการกระจายตัวสม่ำเสมอ)
Tumblr media
Ref: Entropy Randomnes (PDF)
0 notes
ruxoz · 11 years ago
Link
F# beginner guide for those who come from C#
1 note · View note
ruxoz · 11 years ago
Link
0 notes
ruxoz · 11 years ago
Link
Calling Wait() doesn't always mean the thread is blocked!
0 notes
ruxoz · 11 years ago
Quote
Signal-to-Noise ratio แปรผกผันตามจำนวน เอกสาร ที่เพิ่มขึ้น (e.g. Words, wiki, etc.)
me
0 notes
ruxoz · 11 years ago
Photo
Tumblr media
Mystery's solved xD
0 notes
ruxoz · 11 years ago
Link
To look at this flourishing mass of plant life you’d think David Latimer was a green-fingered genius. Truth be told,…
1 note · View note
ruxoz · 11 years ago
Link
weinre is a debugger for web pages, like FireBug (for FireFox) and Web Inspector (for WebKit-based browsers), except it's designed to work remotely, and in particular, to allow you debug web pages on a mobile device such as a phone.
0 notes
ruxoz · 11 years ago
Link
Of the many responses to my editorial on the corruption of Agile, two that disagreed stand out.
0 notes
ruxoz · 11 years ago
Quote
Intelligence: Not because you know everything without questioning, but rather you question everything you think you know.
Anonymous
0 notes
ruxoz · 11 years ago
Link
In case you use it...
What versions of the OpenSSL are affected?
Status of different versions:
OpenSSL 1.0.1 through 1.0.1f (inclusive) are vulnerable
OpenSSL 1.0.1g is NOT vulnerable
OpenSSL 1.0.0 branch is NOT vulnerable
OpenSSL 0.9.8 branch is NOT vulnerable
Bug was introduced to OpenSSL in December 2011 and has been out in the wild since OpenSSL release 1.0.1 on 14th of March 2012. OpenSSL 1.0.1g released on 7th of April 2014 fixes the bug.
0 notes