Skip to content

Instantly share code, notes, and snippets.

View behnam's full-sized avatar
🦊

Behnam Esfahbod behnam

🦊
View GitHub Profile
fn main() {
let mut failed = 0usize;
for i in 0..=u32::max_value() {
if i & 0xffffff == 0 { println!("{}", i); }
let x = f32::from_bits(i);
let r_std = x.round();
let r_hoc = (x+0.5).floor();
if r_std.to_bits() != r_hoc.to_bits() {
println!("round for {} fails", x);
failed += 1;
@rust-play
rust-play / playground.rs
Created October 5, 2018 06:21
Code shared from the Rust Playground
#![allow(warnings)]
#[macro_use]
extern crate lazy_static; // 1.1.0
use lazy_static::LazyStatic;
struct MyFoo {}
impl MyFoo {
@janlelis
janlelis / emoji.md
Last active May 24, 2024 17:01
List of 11.0 Emoji (compiled from emoji-test.txt)

Please note: See character.construction/emoji-categories for more up-to-date listings.

Emoji 11.0

Smileys & People

face-positive

😀 😁 😂 🤣 😃 😄 😅 😆 😉 😊 😋 😎 😍 😘 🥰 😗 😙 😚 ☺️ 🙂 🤗 🤩

@derekjw
derekjw / unit_test.rs
Created May 6, 2016 15:57
Rust unit test macro
macro_rules! unit_tests {
($( fn $name:ident($fixt:ident : $ftype:ty) $body:block )*) => (
$(
#[test]
fn $name() {
let mut $fixt = <$ftype as Fixture>::setup();
$body
$fixt.teardown();
}
)*
@dpk
dpk / gist:8325992
Last active February 27, 2024 05:08
PyICU cheat sheet

PyICU cheat sheet

Because you can't get the docs.

Transliteration

Create a transliterator:

greek2latin = icu.Transliterator.createInstance('Greek-Latin')
@zhuowei
zhuowei / glasslabs.md
Last active December 17, 2015 14:29
Glass Labs experiments: what they do

Glass Lab Experiments

Updated: July 2nd (XE7)

Ron Amadeo of Android Police did a review of these experiments: http://www.androidpolice.com/2013/05/24/google-glasss-hidden-labs-features-ok-glass-everywhere-web-browsing-video-stabilization-and-more-video/

Google Glass has a series of Labs experiments that can be enabled on engineering or userdebug builds. Using APKTool, I've removed that restriction and now they can be enabled with root access.

To start, for example, the SOUND_SEARCH lab, type in a root shell

@mnot
mnot / iri_to_uri.py
Created January 20, 2013 03:15
Convert an IRI to a URI
import urllib
import urlparse
def iri_to_uri(iri, encoding='Latin-1'):
"Takes a Unicode string that can contain an IRI and emits a URI."
scheme, authority, path, query, frag = urlparse.urlsplit(iri)
scheme = scheme.encode(encoding)
if ":" in authority:
host, port = authority.split(":", 1)
authority = host.encode('idna') + ":%s" % port
@metaskills
metaskills / gist:1932866
Created February 28, 2012 14:33
Sass Color Extensions For HSV
class Sass::Script::Color < Sass::Script::Literal
class << self
def new_hsv_float(hue, saturation, value)
zero_to_threesixty = lambda { |x| x < 0 ? 0 : (x > 360 ? 360 : x) }
zero_to_onehundred = lambda { |x| x < 0 ? 0 : (x > 100 ? 100 : x) }
hue = zero_to_threesixty.call((hue * 360.0).round)
saturation = zero_to_onehundred.call((saturation * 100.0).round)
value = zero_to_onehundred.call((value * 100.0).round)
@JeffreyWay
JeffreyWay / gist:1525217
Created December 27, 2011 21:29
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'