Skip to content

Instantly share code, notes, and snippets.

@gliheng
gliheng / overlay_with_hole.dart
Created November 1, 2021 06:30 — forked from flutter-clutter/overlay_with_hole.dart
Flutter overlay with a hole
import 'package:flutter/material.dart';
class OverlayWithHole extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Flutterclutter: Holes")),
body: _getExperimentOne()
);
}
@gliheng
gliheng / main.dart
Created January 10, 2020 02:18
use dom with flutter
@JS()
library vue_app;
import 'package:flutter/material.dart';
import 'dart:ui' as dart_ui_web;
import 'dart:html';
import 'package:js/js.dart';
import 'dart:js';
@JS('console.log')
@gliheng
gliheng / encrypt_openssl.md
Created August 2, 2019 05:49 — forked from dreikanter/encrypt_openssl.md
File encryption using OpenSSL

Symmetic encryption

For symmetic encryption, you can use the following:

To encrypt:

openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt:

@gliheng
gliheng / main.rs
Created January 14, 2019 01:48
Send closures to anther thread
use std::sync::mpsc::channel;
use std::thread;
fn main() {
let (tx, rx) = channel::<Box<dyn Fn() + Send>>();
thread::spawn(move || {
let _ = tx.send(Box::new(|| {
println!("wtf");
}));
let _ = tx.send(Box::new(|| {
@gliheng
gliheng / main.rs
Created January 12, 2019 04:44
rust closure to C style function
use lazy_static::lazy_static;
use std::os::raw::{c_int};
use std::sync::Mutex;
use std::ffi::c_void;
lazy_static! {
static ref REAL_CALLBACK: Mutex<Option<Box<FnMut(c_int, c_int) -> c_int + Send>>> = Default::default();
}
@gliheng
gliheng / main.rs
Last active September 6, 2024 23:39
Mutable lazy_static with a Mutex
#[macro_use]
extern crate lazy_static;
use std::sync::Mutex;
use std::collections::HashMap;
lazy_static! {
static ref HASHMAP: Mutex<HashMap<u32, String>> = Mutex::new({
let mut m = HashMap::new();
m.insert(0, String::from("foo"));
m.insert(1, String::from("bar"));
@gliheng
gliheng / main.rs
Created December 4, 2018 11:04
implement Send and Sync on ffi pointer type
#[macro_use]
extern crate lazy_static;
use std::collections::HashMap;
use std::sync::{Mutex, Arc};
use std::thread;
lazy_static! {
static ref bank: Mutex<HashMap<Man, u32>> = Mutex::new({
let mut m = HashMap::new();
@gliheng
gliheng / lib.c
Created November 26, 2018 07:55
Rust ffi with C
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
void hello()
{
printf("Hello world!\n");
}
@gliheng
gliheng / anination.dart
Last active August 8, 2018 05:51
Seperating concerns with AnimatedBuilder
import 'package:flutter/material.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(
title: 'Flutter Demo',
@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(