Skip to content

Instantly share code, notes, and snippets.

@gliheng
gliheng / gist:13988e03519bc1aaaeb8
Created October 30, 2014 15:24
fast static http server with go
package main
import (
"os"
"log"
"net/http"
)
func main() {
port := "8000"
@gliheng
gliheng / css targeting iphone ipad
Created March 29, 2013 01:40
media query targeting iphone & ipad
<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="http://example.com/iPhone.css" />
<link type="text/css" rel="stylesheet" media="only screen and (min-device-width: 768px) and (max-device-width: 1024px)" href="http://example.com/iPad.css" />
/* iPad [portrait + landscape] */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
}
/* iPhone [portrait + landscape] */
@media only screen and (max-device-width: 480px) {
@gliheng
gliheng / gist:76aefe1ea609dee17a068a1bd78f9f89
Last active November 17, 2017 09:22
This opens an image with raw binary data
'data:image/png;base64,' + btoa(String.fromCharCode.apply(null, new Uint8Array(blob)))
// open this base64 image url in browser
@gliheng
gliheng / main.rs
Created December 14, 2017 12:36
use global static variable in rust
thread_local!(static data: RefCell<HashMap<String, i32>> = RefCell::new(HashMap::new()));
fn main() {
let x = || {
data.with(|c| {
c.borrow_mut().insert("a".to_string(), 1);
});
};
@gliheng
gliheng / main.rs
Created February 5, 2018 02:30
use dynamic typing in rust
use std::collections::HashMap;
use std::any::Any;
fn main() {
let mut h: HashMap<&str, &Any> = HashMap::new();
h.insert("width", &321_i32);
h.insert("msg", &"hello");
if let Some(v) = h.get("width") {
match v.downcast_ref::<i32>() {
@gliheng
gliheng / radial_slider.dart
Created August 7, 2018 05:46
Absolute positioning with CustomSingleChildLayout
import 'dart:math';
import 'package:flutter/material.dart';
class RadialSlider extends StatefulWidget {
double radius;
RadialSlider({
this.radius,
});
@gliheng
gliheng / radial_logo.dart
Created August 7, 2018 10:02
CustomMultiChildLayout
import 'dart:math';
import 'package:flutter/material.dart';
class RadialLayoutDelegate extends MultiChildLayoutDelegate {
int itemCount;
double radius;
RadialLayoutDelegate({this.itemCount = 0, this.radius});
@override
performLayout(Size size) {
@gliheng
gliheng / animation.dart
Created August 8, 2018 03:16
AnimationController demo
import 'package:flutter/material.dart';
import 'radial_logo.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
@gliheng
gliheng / animation.dart
Created August 8, 2018 03:24
Tween with a AnimationController
import 'package:flutter/material.dart';
import 'radial_logo.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
@gliheng
gliheng / animation.dart
Created August 8, 2018 05:09
AnimatedWidget demo
import 'package:flutter/material.dart';
import 'radial_logo.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(