Skip to content

Instantly share code, notes, and snippets.

@gliheng
gliheng / main.dart
Created Jan 10, 2020
use dom with flutter
View main.dart
@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 Aug 2, 2019 — forked from dreikanter/encrypt_openssl.md
File encryption using OpenSSL
View encrypt_openssl.md

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 Jan 14, 2019
Send closures to anther thread
View main.rs
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 Jan 12, 2019
rust closure to C style function
View main.rs
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 Dec 5, 2018
Mutable lazy_static with a Mutex
View main.rs
#[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 Dec 4, 2018
implement Send and Sync on ffi pointer type
View main.rs
#[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 Nov 26, 2018
Rust ffi with C
View lib.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 Aug 8, 2018
Seperating concerns with AnimatedBuilder
View anination.dart
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 Aug 8, 2018
AnimatedWidget demo
View animation.dart
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 Aug 8, 2018
Tween with a AnimationController
View animation.dart
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(
You can’t perform that action at this time.