Skip to content

Instantly share code, notes, and snippets.

View beeender's full-sized avatar
🤡

Chen Mulong beeender

🤡
  • VMware
  • Beijing, China
View GitHub Profile
@beeender
beeender / appsrc-udpsink.c
Last active February 27, 2024 12:57
Gstreamer appsrc streaming though udpsink
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
static GMainLoop *loop;
static void
cb_need_data (GstAppSrc *appsrc,
guint unused_size,
gpointer user_data)
{
@beeender
beeender / MainActivity.java
Created December 28, 2015 07:06
Create Realm on external storage for Android M
package apptest.realm.io.androidmtest;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@beeender
beeender / benchmark.java
Created March 22, 2016 09:41
String conversion benchmark
@Test
public void setString_Benchmark() {
final int TEST_COUNT = 100000;
String[] strings = new String[TEST_COUNT];
for (int i = 0; i < TEST_COUNT; i++) {
strings[i] = UUID.randomUUID().toString();
}
realm.beginTransaction();
long startTime = System.nanoTime();
@Test
public void dateSort() {
Date d20160127 = new GregorianCalendar(2016, Calendar.JANUARY, 27).getTime();
Date d20160227 = new GregorianCalendar(2016, Calendar.FEBRUARY, 27).getTime();
Date d20160510 = new GregorianCalendar(2016, Calendar.MAY, 10).getTime();
Date d20160527 = new GregorianCalendar(2016, Calendar.MAY, 27).getTime();
Date begin = new GregorianCalendar(2016, Calendar.JANUARY, 1).getTime();
Date end = new GregorianCalendar(2016, Calendar.FEBRUARY, 29).getTime();
@beeender
beeender / mem_usage.sh
Created July 15, 2016 09:48
Script to show the average/peak memory usage for Android app.
#!/bin/zsh
OUTPUT=""
PROCESS_EXISTS=false
PROCESS_STARTED=false
COUNT=0
JAVA_HEAP_TOTAL=0
NATIVE_HEAP_TTAL=0
JAVA_HEAP_AVG=0
@Test
public void breaking_changes() throws InterruptedException {
// # Global Realm listeners -- Both Realm & DynamicRealm#
// ## The global Realm change listener will be called immediately when commitTransaction() on the same thread ##
realm.addChangeListener(new RealmChangeListener<Realm>() {
@Override
public void onChange(Realm element) {
// Notice this will be called 3rd in the next event loop in the old implementaion.
RealmLog.info("This will be printed 2nd.");
}
#include <stdlib.h>
#include <time.h>
TEST_CASE("438") {
srand(time(nullptr));
InMemoryTestFile config;
config.automatic_change_notifications = false;
auto r = Realm::get_shared_realm(config);
r->update_schema({
{"filter", {
TEST_CASE("results: benchmark") {
InMemoryTestFile config;
config.cache = false;
config.schema = Schema{
{"object", {
{"int", PropertyType::Int},
{"intIndexed", PropertyType::Int, false, true},
{"string", PropertyType::String},
{"stringIndexed", PropertyType::String, false, true},
}},

CaliburnMicro to make MVVM with WPF easier

Compared with MVC, MVVM does a better job to decouple the Views from other modules. It is supposed to even allow designers to write the View part. But, without the right tools, the View layer can be unbelievably complex. Don't mention the View is usually presented in XML -- the most flexible and complicated thing in the world. If you have experienced writing an application with the raw WPF, you will know what I am saying. The XAML view is getting fatter and fatter, lots of boilerplate code. Sometimes you have to write all of the boilerplate code without code completion since the data binding is dynamic. CaliburnMicro is all about writing less code in a natural way.

Nature way for data binding

Let's start with a simple example:

sub() {
to_replace=""
for var in "$@"
do
if [ -z "$to_replace" ]
then
to_replace=$var
else
RAW_STR=$(echo $RAW_STR | sed "s/${to_replace}/${var}/g")
to_replace=""