GitLab: Key is invalid, Fingerprint cannot be generated

When I try to copy my public key to GitLab, the following error appeared:

  • Key is invalid
  • Fingerprint cannot be generated

The reason is that there are carriage returns in the text. 

We can open the id_rsa.pub, and copy the key as a whole line, and then paste to the GitLab to solve this problem.

 

 

N!末尾有多少个0?N!的二进制表示中最低位1的位置

1. N!末尾有多少个0?

等于看N!是10 的几次方,也就看N!中质因数2和5的个数。如果N!=(2^x) * (3^y) * (5^z) *..。,那0的个数就是M=min(x, z),很显然N!质因数中2出现的次数比5多(因为每隔2个数就出现一个质因数2,每隔5个数才出一个质因数5),于是M=z。所以N!末尾有多少个0取决于N!含有多少个质因数5,M=z=N/5+N/25+N/125+N/625+…,比如1024!的末尾有多少个0,

是5的倍数的数有: 1024 / 5 = 204个
是25的倍数的数有:1024 / 25 = 40个
是125的倍数的数有:1024 / 125 = 8个
是625的倍数的数有:1024 / 625 = 1个
所以1024! 中总共有204+40+8+1=253个因子5,也就是说1024! 末尾有253个0。

2. N!的二进制表示中最低位1的位置

对于一个数除以2, 相当于把这个数的二进制表示向右移一位(符号位不变)。所以如果N!=(2^x) * (3^y) * (5^z) *…的话,那把这个数的二进制表示向右移x位,最低位就会是1,所以最低位1的位置M=1+x=1+ N/2+N/4+N/8+….

Embedding all fonts in PDF files

Trying to submit a LaTeX/pdflatex/pdftex-generated publication via IEEE’s PDF eXpress (a trademark of IEEE) but it keeps insisting that the font data is not completely embedded? This may originate from embedded graphics (EPS, PDF) that themselves “miss” the fonts. LaTeX won’t do anything for you, sorry. But here is a clue: Print to a PDF creation tool and tell that to embed all fonts. Here is how:

1. Install PDFCreator (basically a free and open source alternative to the bis PDF company’s Distiller).
2. Print the LaTeX-generated PDF-File from Adobe Reader to the new PDFCreator virtual printer. Be sure to check this:
a) Set the right page format (A4/Letter)
b) Uncheck “Print as image” in the Advanced print options. Otherwise the resulting PDF contains one image per page instead of vector graphics. You can check this by ensuring crisp characters after zooming in to great magnification.
c) Enable color printing in the PDFCreator “printer” options (if desired).
d) Disable resizing and rotation options to preserve the original page layout.
A dialog comes up that asks for metadata to embed. Before clicking “Save”, a “Settings” button leads to a dialog that allows general settings as well as settings for the target file formats to be made. Under the “PDF” file format, find the settings for fonts and ensure that the “Embed all fonts” box is checked.
Save the generated PDF and submit it to PDF eXpress.

Setup our project on GitHub

For example, our aim is to setup an project named “HelloWorld” on GitHub.

1. Go to GitHub website to create a repository named “HelloWorld”.

2. In our local computer, create a folder named “HelloWorld” or other names (local name can be different from the GitHub repository name, but I suggest to use the same name for consistency) in any disk (either C/D/E/F is okay, not necessarily in the .ssh directory).
We can do this step either in Git Bash or not.

3. Open Git Bash, go to the folder, do initilization
git init

4. Tell git what you want to do (For example, add a file named “readme”)
git add readme
git commit -m ‘add file readme’

5. Push the commit to GitHub
git remote add origin git@github.com:jincheng9/HelloWorld.git (use origin to point to the HelloWorld.git in GitHub)
git push origin master (push the commit to the master branch of HelloWorld repository)

Setup Git and GitHub on Windows

1. Register on GitHub https://github.com/

2. Download and Install Git on your computer: http://git-scm.com/downloads (select “Windows”)

3. Configure Git and GitHub on you computer
–open Git Bash
–configure username (just type git config –global user.name “Your Name Here”)
–configure email (just type git config –global user.email “your_email@example.com”)
–generate ssh key (refer to https://help.github.com/articles/generating-ssh-keys)

References: https://help.github.com/articles/set-up-git

Android Development 101-Modify “Hello World” app

This post covers how to run android development codes directly on smartphones (not AVDs) and how to modify the “Hello World” app to create powerful apps.

1. How to run android development codes directly on smartphones?
In order to run android development codes on smartphones, we need to do two things. On the smartphone’s side, we need to launch the “USB debug mode”. On the PC’s side, we need to install the driver for the smartphone. Then we plug in the smartphone to the PC, and we can see the phone shown at the “Device View” of Eclipse. If we run the codes as “Android Application”, then we can choose to run the codes on our smartphones. If the codes executes successfully, the app will automatically show in the smartphone.

2. How to modify “Hello World” app?
There is a file “activity_main.xml” in the directory of project->res->layout. Open this file and you will find code like this.

TextView in activity_main.xml

TextView in activity_main.xml


And in the project->res->values->string.xml, you will find code like this.
strings.xml

strings.xml

Obviously, @string/hello_world in activity_main.xml refers to the content defined in the strings.xml. And the content is “Hello world!”. So if we want the app to show something different, we can change the content of hello_world or create another string like hello_world. For example, if we want to show “The Lord of Rings”, we can modify the activity_main.xml and strings.xml as follows.
ringstringRing

We can also open the Graphical Layout of activity_main.xml to use GUI to insert texts or images to the app.
3. Some Tips
1. In AndroidManifest.xml, we can modify SDK version to let our app run in older or latest smartphones.
2. Use “Quick Access” to find the View of “File Explorer”. Under this view, we can transfer files between PCs and smartphones.
3. The R.java in the project->gen directory is automatically generated. Generally, this file will automatically refresh if we modify the project. If not, we can just delete R.java and this file will be regenerated.

OOP in JavaScript

In this post, I discuss some basic concepts about OOP (Object Oriented Programming) in JavaScript, including how to create objects and classes, how to set properties and methods for a class to be private and public, how to do inheritance, etc.

For more details on the OOP, you can refer to this post: http://www.ibm.com/developerworks/cn/web/1304_zengyz_jsoo/.

1. How to create objects directly?

In general, there are two ways to create an object in JavaScript. Below are two examples.


var obj = {
  property1: value1,
  property2: value2,
  method1: function() {
     return this.property1;
  },
  method2: function(value) {
    this.property2 = value;
  }
};

var obj = new Object();
obj.property1 = value1;
obj.property2 = value2;
obj.method1 = function() {
  return this.property1;
};
obj.method2 = function(value) {
  return this.property2 = value;
};

2. How to create classes?


function Person(name, age) {
  this.name = name;
  this.age = age;
  this.sayName = function(){
     console.log("I am "+this.name);
  };
}
obj me = new Person("Jincheng", 23);
me.sayName();

3. How to add methods for a class?


function Person(name, age) {
  this.name = name;
  this.age = age;
  this.sayName = function(){
     console.log("I am "+this.name);
  };
}
obj me = new Person("Jincheng", 23);
me.sayName();
//Add method makeFriends to class Person
Person.prototype.makeFriends = function(friendName) {
  console.log(this.name+" make friends with "+friendName);
};
me.makeFriends("Jane");

Tips: For each class, there is a corresponding prototype. If we want to add a method to an already-defined class, then we use the prototype of this class, just like what I show in the above example. After adding a method to the class, all objects of this class will automatically have this method.

4. How to set properties and methods to be private and public?

In default, the properties and methods of a class is public, then we can access the properties and methods outside the class. If we want some properties and methods to be private, we need to define the properties as variables and methods as functions as if this class doesn’t exist. Below is an example.

function Person(name, age, sex) {
  this.name = name; //defaultly, it is public
  var age = age;//the property "age" is private
  this.method1 = function() { //public function
    console.log("method1");
  };
  var method2 = function() {//private function
    console.log("method2");
  };
}
var me = new Person("Jane");
console.log(me.name);
console.log(me.age);//it's wrong, since the property age is private
me.method1();
me.method2();//it's wrong, since the method method2 is private

5. How to do inheritance?


function Animal(name, numLegs) {
  this.name = name;
  this.numLegs = numLegs;
  this.bark = function() {
    console.log("I am barking");
  };
}
function Penguin(name) {
  this.name = name;
  this.numLegs = 2;
}
//class Animal becomes the father of Penguin
Penguin.prototype = new Animal();
var penguin = new Penguin("jack");
penguin.bark();//class Penguin inherits method bark from its father