技術情報
- 2021年02月09日
- 技術情報
Pseudocode
Pseudocode is an informal form of programming description that does not require any strict programming language syntax or underlying technology considerations. Used to create an outline or draft of a program. Pseudocode summarizes the flow of a program, but excludes the underlying details. Systems designers write pseudocode to ensure that programmers understand the requirements of a software project and align the code accordingly.
A Pseudocode is a prototype sample, model, or early release of a product created for the purpose of testing concepts and for learning purposes. They help us learn without fully implementing our solutions. When developing user interfaces for our applications, we have several prototypes before the final interface. Some examples of these are wire frames, graphic designs, and mockups.
This is the way how to write pseudo code.
- Organize your task sequence and write your pseudocode accordingly.
- Start with the declaration of a pseudocode that states the main goal or goal.
We have to know there are some KEYWORDS to be used in pseudo code.
These are for start and end of a program
BEGIN, END
These are for condition statements.
IF, ELSE, ENDIF, DO, WHILE, ENDWHILE, REPEAT, UNTIL, CASE
These are for user inputs.
INPUT, GET, READ , SET
These are for displaying results.
PRINT, SHOW
Here is some sample pseudo codes.
//Conditional statement if
if "1"
print "this is 1"
if "2"
print "this is 2"
//Case condition
INPUT number
CASE number of
1: PRINT "1"
2: PRINT "2"
3: PRINT "3"
DEFAULT
PRINT "0"
ENDCASE
//While Loop
Set index to 0
WHILE index is GREATER THAN 1
PRINT index
INCREASE index BY 1
END
Function
Function sample
PRINT 'hello world'
Endfunction
There are still more keywords and syntax structures of writing pseudo codes but I think you will get the idea by reading this blog.
By Yuuma
yuuma at 2021年02月09日 07:07:22
- 2021年02月01日
- 技術情報
Free Hosting Services that I know
Today, I would like to talk about hosting services that are available to upload your site for free. Although there are thousands of services that are giving free, I will share some good services among these which I know. Let’s get started.
Github Pages
Github is a company that hosts code repositories, collections of code for projects. Github has a feature called Github Pages, which makes it easy and free for you to create a multi-file website hosted on yourusername.github.io. GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files directly from a repository on GitHub, optionally runs the files through a build process, and publishes a website. You can see here. When uploading source code, it is necessary to consider whether the source code is safe to be released to the public.
Netlify
Netlify allows you to create a website using the repository on the git platform. You just need to choose the repository and run the deployment command. After the deployment is complete, your site will be live. You can see here.
AWS Free Tier
Amazon Web Services is an integrated provider of cloud-based computing solutions. One of the Services they provide is Web Site Hosting. AWS offers you a one year free account called AWS Free Tier and you can test and use variety of products from AWS like EC2, S3, RDS and so on. I know it is a little bit hard to consume the UI of AWS but it will improve your server administration knowledge. Be sure to test it out. See here for more detail.
Website Builders
There are some other free services that has website builder like wordpress. So you don’t have to write a single line of code and can build your website within minutes. For example wordpress, wix, weebly. But these services might also have pricing features, so they might force you to buy their product by somehow.
By Yuuma
yuuma at 2021年02月01日 06:19:25
- 2021年01月25日
- 技術情報
SQL Joins
Today I would like to talk about MySQL joins along with some practical example queries.
Inner Join
2テーブルの中で同じレコードだけ出る。
(return only matching records from both tables)
Left Join
left テーブルは全レコードが出る、right テーブルのは同じレコードだけ
(return all records from the left table, and only the matched records from the right table)
Right Join
right テーブルは全レコードが出る、leftテーブルのは同じレコードだけ
(return all records from the right table, and only the matched records from the left table)
Full Outer Join
同じレコードが有る時全部レコードが出る。
(return all records from both tables if there is match record between them)
Inner Join Query Example
SELECT column(s)
FROM tb1
INNER JOIN tb2
ON tb1.column = tb2.column;
Left Join Query Example
SELECT column(s)
FROM tb1
LEFT JOIN tb2
ON tb1.column = tb2.column;
Right Join Query Example
SELECT column(s)
FROM tb1
RIGHT JOIN tb2
ON tb1.column = tb2.column;
Full Outer Join Query Example
mysql doesn’t support full join syntax directly so we can use this as an alternative.
(full join = left + right join)
SELECT column(s)
FROM tb1
LEFT JOIN tb2 ON tb1.column = tb2.column;
LEFT JOIN tb3 ON tb1.column = tb3.column;
UNION
SELECT column(s)
FROM tb1
SELECT column(s)
FROM tb1
RIGHT JOIN tb2 ON tb1.column = tb2.column;
RIGHT JOIN tb3 ON tb1.column = tb3.column;
yuuma at 2021年01月25日 04:22:16
- 2021年01月18日
- 技術情報
Calculation of time elapsed in PHP
Today I would like to write some code about calculating time elapsed in PHP. Especially if we want to know the elapsed time of inserted records (seconds, minutes, hours , days etc).
For example – Posted 1 週前、3 時間前、50 分間前、30秒間前。
Here is our function to calculate the time eclipse
<?php
function time_elapsed($datetime) {
$now = new DateTime;
$ago = new DateTime($datetime);
//getting the time differences.
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7); //week
$diff->d -= $diff->w * 7; //day
//string arrays of formats
$string = array(
'y' => '年',
'm' => '月',
'w' => '週',
'd' => '日',
'h' => '時間',
'i' => '分',
's' => '秒',
);
//mapping the time difference and format
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v;
} else {
unset($string[$k]);
}
}
//only getting the first array key and value
$string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . '前' : 'ちょうど今';
}
I have included the comments in code so that you can be able to understand it. Let’s call our function to test.
echo time_elapsed("2020-12-06 11:24:25"); //output 1 月前
echo time_elapsed(date("Y-m-d H:i:s")); //output ちょうど今
PS. we have to care about our server timezone when we are dealing with Datetime functions
By Yuuma
yuuma at 2021年01月18日 04:56:29
- 2021年01月12日
- 技術情報
Using controller function directly in Laravel blade
Today I would like to talk about using the function from controller directly on your blade view files.
Normally we wrote codes relating with application logic and database and then pass the data to specific view files. But what if we like to use the function from controller directly ?
We can create a static function in controller and then can directly be called from blade file without instantiating the class. Let me write a sample example.
Firstly, we will create a static function in controller. Why static function ?
If we create a normal function, we will need to instantiate the class in view file like this `new Controller()` which will be a mess in view files. Static function can be directly called using scope resolution (::) operator.
<?php
namespace App\Http\Controllers;
class HomeController extends Controller
{
public static function greet()
{
return "Hello World";
}
}
After that we can call the above controller function directly by providing the namespace of the controller and function using scope resolution operator like this.
<p>
{{ App\Http\Controllers\HomeController::greet() }}
<!-- output - Hello World -->
</p>
By Yuuma
yuuma at 2021年01月12日 10:00:59