Skip to content

Instantly share code, notes, and snippets.

View infinitypaul's full-sized avatar
🎯
Near a code editor

Paul Edward infinitypaul

🎯
Near a code editor
View GitHub Profile
@infinitypaul
infinitypaul / toString.php
Created December 7, 2019 14:25
toString.php
<?php
class MyName
{
public function __toString()
{
return 'I Am A Genius';
}
}
@infinitypaul
infinitypaul / characterOnce.js
Last active December 3, 2019 10:07
Remove Duplicate Character
function characterOnce(str){
let frequency = {};
let newWord ='';
for(let i=0; i<str.length; i++){
let character = str.charAt(i)
if(frequency[character]){
frequency[character]++
} else {
frequency[character] = 1
}
const MyComponent = props => {
const innerFunction = useCallback(() => {
// do something!
});
useEffect(() => {
innerFunction();
// The effect calls innerFunction, hence it should declare it as a dependency
// Otherwise, if something about innerFunction changes (e.g. the data it uses), the effect would run the outdated version of innerFunction
}, [innerFunction]);
const MyComponent = props => {
const innerFunction = () => {
// do something!
};
useEffect(() => {
innerFunction();
// The effect calls innerFunction, hence it should declare it as a dependency
// Otherwise, if something about innerFunction changes (e.g. the data it uses), the effect would run the outdated version of innerFunction
}, [innerFunction]);
const MyComponent = props => {
const innerFunction = () => {
// a function in a function!
// this function object (stored in the 'innerFunction' constant) is constantly re-built
// to be precise: It's re-built when MyComponent is re-built
// MyComponent is re-built whenever its 'props' or 'state' changes
};
};
<?php
class User {
/**
* @var \Logger
*/
public $logger;
public function __construct(Logger $logger)
{
<?php
class User {
public function create(array $data){
try {
//Save User To Database
} catch (Exception $exception){
$this->logError($exception->getMessage());
}
}
@infinitypaul
infinitypaul / userrepository.php
Created June 20, 2019 10:09
Dependency injection using constructor
<?php
class UserRepository
{
private $db;
private $config;
private $users;
public function __construct(Database $db, Config $config, User $users)
{
.Backdrop {
width: 100%;
height: 100%;
position: fixed;
z-index: 100;
left: 0;
top: 0;
background-color: rgba(0,0,0,0.5);
}
@infinitypaul
infinitypaul / Modal.module.css
Last active January 13, 2020 14:10
React Reusable Modal
.Modal {
position: fixed;
z-index: 500;
background-color: white;
width: 70%;
border: 1px solid #ccc;
box-shadow: 1px 1px 1px black;
padding: 16px;
left: 15%;
top: 30%;