Skip to content

Instantly share code, notes, and snippets.

View weird-coon's full-sized avatar
🦝
Surprise!

Quyen Luu weird-coon

🦝
Surprise!
View GitHub Profile
//Self-Signed Certificate for using with VS Code Live Server
//Save both files in a location you will remember
1. create a private key
openssl genrsa -aes256 -out localhost.key 2048
// you will be prompted to provide a password
//this will create localhost.key (call it whatever you like)
2. create the certificate
@weird-coon
weird-coon / redirect_back.js
Created June 8, 2018 03:45
[JS] Redirect to previous page
/**
* Redirect to previous page
*
* @returns {boolean}
*/
function redirect_back() {
// From other domain or from direct
if (document.referrer.split('/')[2] != location.hostname) {
location.href = '/';
} else {
@weird-coon
weird-coon / http_statuses.php
Last active June 8, 2018 03:45
[PHP] Array of HTTP response status codes and messages
<?php
/**
* @var array An array of status codes and messages
*
* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* for the complete and approved list, and links to the RFC's that define them
*/
public static $statuses = array(
100 => 'Continue',
101 => 'Switching Protocols',
@weird-coon
weird-coon / validateDate.php
Last active June 8, 2018 03:46
[PHP] Validate date PHP function with date format. Return true if valid date and other side.
<?php
/**
* Valid datetime format
*
* @param string $date
* @param string $format
* @return bool
*/
private function validate_date($date, $format = 'Y/m/d')
{
@weird-coon
weird-coon / padNumber.php
Last active June 8, 2018 03:46
[PHP] Add zero before number
<?php
/**
* Padding a time on the left format time 1 -> 01
*
* @access private
* @param string $num 時間
* @return string time after format
*/
public function addZeroBeforeNumber($num) {
return sprintf('%02d', $num);
@weird-coon
weird-coon / japan_pref.php
Last active June 8, 2018 03:46
[PHP] Japanese pref ids and names
<?php
$pref_ids = array(
'01' => '北海道', '02' => '青森県', '03' => '岩手県', '04' => '宮城県', '05' => '秋田県',
'06' => '山形県', '07' => '福島県', '08' => '茨城県', '09' => '栃木県', '10' => '群馬県',
'11' => '埼玉県', '12' => '千葉県', '13' => '東京都', '14' => '神奈川県', '15' => '新潟県',
'16' => '富山県', '17' => '石川県', '18' => '福井県', '19' => '山梨県', '20' => '長野県',
'21' => '岐阜県', '22' => '静岡県', '23' => '愛知県', '24' => '三重県', '25' => '滋賀県',
'26' => '京都府', '27' => '大阪府', '28' => '兵庫県', '29' => '奈良県', '30' => '和歌山県',
'31' => '鳥取県', '32' => '島根県', '33' => '岡山県', '34' => '広島県', '35' => '山口県',
'36' => '徳島県', '37' => '香川県', '38' => '愛媛県', '39' => '高知県', '40' => '福岡県',
@weird-coon
weird-coon / strip_tags.sql
Last active June 14, 2018 08:11
[MySQL] Reproduces PHP strip_tags () with Mysql and search keywords from the result of excluding HTML tags.
DELIMITER //
DROP FUNCTION IF EXISTS `STRIP_TAGS`//
CREATE FUNCTION STRIP_TAGS( x text) RETURNS text
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT;
DECLARE ends INT;
IF x IS NOT NULL THEN
SET sstart = LOCATE('<', x, 1);
@kijtra
kijtra / strip_tags.sql
Created July 9, 2012 07:11
[MySQL] PHPでいうstrip_tags()関数
DELIMITER //
DROP FUNCTION IF EXISTS `STRIP_TAGS`//
CREATE FUNCTION STRIP_TAGS( x longtext) RETURNS longtext
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT UNSIGNED;
DECLARE ends INT UNSIGNED;
IF x IS NOT NULL THEN
SET sstart = LOCATE('<', x, 1);
@jaysonrowe
jaysonrowe / FizzBuzz.js
Created January 11, 2012 01:39
FizzBuzz JavaScript solution
for (var i=1; i <= 20; i++)
{
if (i % 15 == 0)
console.log("FizzBuzz");
else if (i % 3 == 0)
console.log("Fizz");
else if (i % 5 == 0)
console.log("Buzz");
else
console.log(i);