Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- OUTPUT



  jsonSerialize() in extended class

Since PHP 5.4.0, there is a convenient interface JsonSerializable which can be used to indicate that a PHP object can be serialized to JSON object. It has only one method which should be implemented by any class which implements this interface. The method is named jsonSerialize(). It's really easy to serialize an object to JSON object. Here is one example: <?php class ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; ...

   JSON,jsonSerialize,Inheritance,extends     2014-07-26 05:54:00

  Understanding an interesting JavaScript map function question

With the evolvement of JavaScript, lots of new features have been added this old but robust language.  Among them are lots of functional programming language related functions like map, filter, each etc. In this post, we will cover one function map and its interesting behavior. Before dive into the details, let first take an example, do you know the output of below function call? ['1', '7', '11'].map(parseInt) You may think that it's easy and the output would be [1, 7, 11] Can you try to ru...

   JAVASCRIPT,MAP,FUNCTIONAL PROGRAMMING     2019-06-14 08:34:46

  Understand this in JavaScript

In JavaScript, this is always pointing to the owner of a function or a method. Function Let's check out function first. function introduce() {      alert("Hello, I am Laruence\r\n"); } For this function, what does this point to? In JavaScript, a global function's owner is the current page, i.e, the window object. Because its a method of the window object if we define a global function. Now you should know the this will point to the window object in the above function. ...

   JavaScript,this,event,call     2013-04-03 04:10:03

  A strange behavior of printing struct with nested struct in GoLang

Normally when trying to print a struct , we would use %v to show all data of the struct. It will print the default format for each field in the struct. %v the value in a default format when printing structs, the plus flag (%+v) adds field names But recently we observed a strange behavior when printing a struct with nested struct which has a String() string implemented, the %v format prints an 'unexpected' output per our understanding.   Let's see the example snippet first. pa...

   PROGRAMMING,GOLANG     2018-10-29 09:59:49

  Different types of keystore in Java -- JCEKS

JCEKS stands for Java Cryptography Extension KeyStore and it is an alternative keystore format for the Java platform. Storing keys in a KeyStore can be a measure to prevent your encryption keys from being exposed. Java KeyStores securely contain individual certificates and keys that can be referenced by an alias for use in a Java program. The process of storing and loading different entries in JCEKS is similar to what JKS does. So please refer to the article Different types of keystore in Java -...

   Java,KeyStore,JCEKS,Tutorial     2015-01-05 00:30:56

  Start to work with rollup.js to pack JS files

rollup.js is a module bundler for JavaScript. It compiles small piece of JavaScript modules spreading in different files into a single larger standardized ES code file. This post will show some entry level usage for this library. Introduction Normally a bundler tool would compile a few small JavaScript files into a single JavaScript so that web browser can read, parse and render it properly. A bundler tool may be needed because of a few reasons: Some early stage browsers don't understand module...

   ROLLUP.JS,COMMONJS,ES MODULE,BUNDLE,WEBPACK     2022-06-12 00:00:14

  PHP's Output Buffering

While profiling our application I came across a a rather strange memory usage by the ob_start() function. We do use ob_start() quite a bit to defer output of data, which is a common thing in many applications. What was unusual is that 16 calls to ob_start() up chewing through almost 700kb of memory, given that the data being buffered rarely exceeds 1-2kb, this was quite unusual. I started looking at the C code of the ob_start() function and found this interesting bit of code inside php_sta...

   PHP,Memory,ob_start(),source,40kB     2011-12-08 10:20:32

  Check file readability in Java

File operation is quite platform dependent. Although Java is a cross platform programming language, the file operation in Java is also platform dependent. The obvious evidence is the file permission check. In Java, we can call canRead(), canWrite() and canExecutable() to check whether the program can read, write or execute the file specified. However, on Windows, when we call canRead() on a File object, we may get unexpected result. Actually, on Windows, when we call canRead() on a File object, ...

   Java,Files,Readable,Check     2013-12-05 06:10:15

  Stub Mixlib::ShellOut and shell_out in Ruby unit testing

Unit testing is part of software development to ensure the tiny component of a function can work as designed. Different frameworks and tools can be used to run unit testing for different programming languages. In Ruby, one popular unit testing framework is Rspec, or Chefspec if you are writing Chef recipes. While writing Chef recipes, some low level commands(DOS commands or shell commands) need to be executed on the managed resource to perform actions or gather information. For example, lis...

   RUBY,UNIT TESTING,RSPEC,CHEFSPEC,SHELL_OUT     2016-11-11 00:14:46

  Beauty of code : How to write graceful PHP code

Writing good code is an art. In order to achieve this, it is necessary to develop good programming habits at the beginning. Good programming habits not only contributes to the early project design (modular),but also allows you to the code easier to understand, so that the maintenance of the code is easier. Bad programming habits will result in more code bugs, and will make future maintenance work difficult. We introduce some good programming habits taking PHP as example. Hope this will help you....

   PHP,Good code     2012-08-26 12:23:03