Blog Archive

Saturday, December 30, 2017

How to Auto Execute Commands/Scripts During Reboot or Startup

How to Auto Execute Commands/Scripts During Reboot or Startup:



Executing Linux Scripts at Logon and Logout

To execute a script at logon or logout, use ~.bash_profile and ~.bash_logout, respectively. Most likely, you will need to create the latter file manually. Just drop a line invoking your script at the bottom of each file in the same fashion as before and you are ready to go.


'via Blog this'

Friday, December 29, 2017

什么是人才

6000亿!沉默已久的华为突然抛下重磅炸弹(图) | www.wenxuecity.com: " 



 任正非说了三句关于人才的话,成为了经典。
  “一个人不管如何努力,永远也赶不上时代的步伐,更何况在知识爆炸的时代。只有组织起数十人、数百人、数千人一同奋斗,你站在这上面,才摸得到时代的脚。”
  “也许是我无能、傻,才如此放权,使各路诸侯的聪明才智大发挥,成就了华为。”
  “什么是人才,我看最典型的华为人都不是人才,钱给多了,不是人才也变成了人才。”



'via Blog this'

Wednesday, December 27, 2017

8. Commiting the changes

8. Commiting the changes:

how to handle

git commit

message box



'via Blog this'

[c++][study notes]Polymorphism in C++

Polymorphism in C++:



Virtual Function

virtual function is a function in a base class that is declared using the keyword virtual. Defining in a base class a virtual function, with another version in a derived class, signals to the compiler that we don't want static linkage for this function.
What we do want is the selection of the function to be called at any given point in the program to be based on the kind of object for which it is called. This sort of operation is referred to as dynamic linkage, or late binding.


'via Blog this'

WebRTC中的Opus编码揭秘 - CSDN博客

WebRTC中的Opus编码揭秘 - CSDN博客:

"开启DTX

 DTX 是
Discontinuous Transmission的简称,这个特性是在用户不说话时不传输语音,这样可以节省点带宽。

默认WebRTC是不开启这个特性的,要开启DTX,只需要在a=ftmp这一行中加入usedtx=1就行"



'via Blog this'

Thursday, December 21, 2017

Java Native Interface (JNI) for calling C-libraries

Reference:

https://youtu.be/4B-cNXYNRDo





Step 1: prepare files (printmsg.c & main.java)



cat printmsg.c

#include<stdio.h>



void printmsg()

{

printf("hello there world from Gang\n");

}





cat main.java

class MyMain{

public native void printmsg();

static

{

System.loadLibrary("prtmsg");

}

public static void main(String[] args){

MyMain hello = new MyMain();

hello.printmsg();



}





}





Step 2: compileing caller (JAVA)

javac main.java # output MyMain.class

javah MyMain #output MyMain.h





cat MyMain.h

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class MyMain */



#ifndef _Included_MyMain

#define _Included_MyMain

#ifdef __cplusplus

extern "C" {

#endif

/*

 * Class:     MyMain

 * Method:    printmsg

 * Signature: ()V

 */

JNIEXPORT void JNICALL Java_MyMain_printmsg

  (JNIEnv *, jobject);



#ifdef __cplusplus

}

#endif

#endif





Step 3: re-editing callee (C)

#edit printmsg.c to include "MyMain.h" & modify function signature



#include<stdio.h>

#include "MyMain.h"



//void printmsg(){

JNIEXPORT void JNICALL Java_MyMain_printmsg

  (JNIEnv *env, jobject obj)

{

printf("hello there world from Gang\n");

}





Step 4: compiling callee (C)

gcc -shared -o libprtmsg.so printmessage.c -fPIC -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux



Step 5: preparing environment & testing:

cat build.sh

export LD_LIBRARY_PATH=`pwd`

echo $LD_LIBRARY_PATH

unset LD_LIBRARY_PATH

java MyMain





'via Blog this'

Wednesday, December 13, 2017

merge - Finding and merging down intervalls in Perl - Stack Overflow

merge - Finding and merging down intervalls in Perl - Stack Overflow:







https://stackoverflow.com/questions/42928964/finding-and-merging-down-intervalls-in-perl





#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

my %ranges;

#iterate line by line. 
while (<>) {
   chomp;
   #split by line
   my ( $name, $start_range, $end_range ) = split;
   #set a variable to see if it's within an existing range. 
   my $in_range = 0;
   #iterate all the existing ones. 
   foreach my $range ( @{ $ranges{$name} } ) {

      #merge if start or end is 'within' this range. 
      if (
         ( $start_range >= $range->{start} and $start_range <= $range->{end} )

         or

         ( $end_range >= $range->{start} and $end_range <= $range->{end} )
        )
      {


         ## then the start or end is within the existing range, so add to it:
         if ( $end_range > $range->{end} ) {
            $range->{end} = $end_range;
         }
         if ( $start_range < $range->{start} ) {
            $range->{start} = $start_range;
         }
         $in_range++;
      }

   }
   #didn't find any matches, so create a new range identity. 
   if ( not $in_range ) {
      push @{ $ranges{$name} }, { start => $start_range, end => $end_range };
   }
}

print Dumper \%ranges;

#iterate by sample
foreach my $sample ( sort keys %ranges ) {
   #iterate by range (sort by lowest start)
   foreach
     my $range ( sort { $a->{start} <=> $b->{start} } @{ $ranges{$sample} } )
   {
      print join "\t", $sample, $range->{start}, $range->{end}, "\n";
   }
}
Outputs with your data:
SampleA 100 600 
SampleA 700 800 
SampleA 900 1100    
SampleA 1200    1900    
SampleB 700 900 
SampleB 1000    1800    
SampleB 1900    2600    
SampleB 3000    3600    
This probably isn't the most efficient algorithm though, because it checks all the ranges - but you probably don't need to, because the input data is ordered - you can just check the 'most recent' instead.


'via Blog this'