Skip to content

Instantly share code, notes, and snippets.

View thexdev's full-sized avatar
🧬
Experiment

M. Akbar Nugroho thexdev

🧬
Experiment
View GitHub Profile
@thexdev
thexdev / text2binary.js
Created January 30, 2020 11:06
JavaScript function to convert plain text to binary
const text2binary = (text = "") => {
return text === ""
? text
: text
.split("")
.map(char => `${char.charCodeAt(0).toString(2)} `)
.join("");
};
@thexdev
thexdev / binary2text.js
Last active January 30, 2020 11:08
JavaScript function to convert binary text to plain text
const binary2text = (binaryText = "") => {
return binaryText === ""
? binaryText
: binaryText
.split(" ")
.map(binary => parseInt(binary, 2))
.map(number => String.fromCharCode(number))
.join("");
};
@thexdev
thexdev / store-command-output-into-file.sh
Created December 17, 2019 12:26
Insert the output of your bash command into a file (you can choose the specific file extention too)
# Here i'm trying to extract detailed information
# on the hardware configuration of my computer
# with html format then display it to the browser.
sudo lshw -html > index.html && firefox index.html
@thexdev
thexdev / position-and-center-image.css
Created December 13, 2019 16:54
Position and center the image to scale nicely on all screens
.hero-image {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
@thexdev
thexdev / css-darker-background-effect.css
Last active December 13, 2019 16:52
Add darker background effect to the image
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("photographer.jpg");
@thexdev
thexdev / php-mysql-datetime-format.php
Last active December 12, 2019 13:38
PHP date function syntax to fill the value in mysql datetime column.
<?php
$now = date("Y-m-d H:i:s");
@thexdev
thexdev / bg-img-with-gradient-overlay.css
Last active December 12, 2019 17:01
CSS snippet to make a background image with gradient color overlay
#bg-img-overlay {
background-image:
linear-gradient(
to right,
rgba(15, 12, 41, 0.7),
rgba(48, 43, 99, 0.7),
rgba(36, 36, 62, 0.7)
),
url('https://source.unsplash.com/random/800x600');
}
@thexdev
thexdev / system-tmp-directory.php
Last active October 22, 2023 19:23
Solve CodieIgniter error with message: mkdir(): Invalid path and Filename: drivers/Session_files_driver.php. This usually happen on mac.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
@thexdev
thexdev / bubblesort.algo.js
Last active October 7, 2019 04:44
Bubble sorting algorithm in JavaScript
/**
* Bubble sorting algorithm in JavaScript.
*
* Here i'm using arrow function and ES6, but you can use native function and ES5 instead.
*
* @param {array} arr Unsorted Array
* @return {array}
*/
const bubbleSort = arr => {
let swapped;
@ChrisDobby
ChrisDobby / forwardRef.tsx
Created July 30, 2019 20:03
Example of React component in Typescript using forwarding refs
import * as React from "react";
const Forward = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => (
<div ref={ref} style={{ width: "100%", height: "30px", backgroundColor: "green" }} />
));
function ForwardRef() {
const divRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {