Skip to content

Instantly share code, notes, and snippets.

View lamsmallari's full-sized avatar
💭
🌳

Lam lamsmallari

💭
🌳
View GitHub Profile
@gaearon
gaearon / Classes.js
Created May 27, 2020 17:38
Beneath Classes: Prototypes
class Spiderman {
lookOut() {
alert('My Spider-Sense is tingling.');
}
}
let miles = new Spiderman();
miles.lookOut();
@swyxio
swyxio / createCtx-noNullCheck.tsx
Last active May 4, 2023 02:15
better createContext APIs with setters, and no default values, in Typescript. this is documented in https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/README.md#context
// create context with no upfront defaultValue
// without having to do undefined check all the time
function createCtx<A>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = React.useContext(ctx)
if (!c) throw new Error("useCtx must be inside a Provider with a value")
return c
}
return [useCtx, ctx.Provider] as const
@toraritte
toraritte / add_user_and_reset_password_with_Firebase_admin_on_node.md
Last active May 10, 2024 13:10
Sending password reset email after user has been created with Firebase Admin SDK (Node.js)

Sending password reset email after user has been created with Firebase Admin SDK (Node.js)

1. Install Firebase's Node modules

Install the Firebase Node modules:

$ npm install firebase firebase-admin --save
@bradtraversy
bradtraversy / pdocrash.php
Last active January 31, 2025 15:50
PDO & Prepared Statements Snippets
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$dbname = 'pdoposts';
// Set DSN
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Create a PDO instance
@alirezas
alirezas / fade.js
Created February 13, 2017 10:54
fadeIn & fadeOut in vanilla js
function fadeOut(el){
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .1) < 0) {
el.style.display = "none";
} else {
requestAnimationFrame(fade);
}
})();
@ccurtin
ccurtin / Detect-if-IE.js
Created November 23, 2015 06:41
Detect if IE and add class to html/body..
/**
* detect IE
* returns version of IE or false, if browser is not Internet Explorer
*/
(function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
@dom082186
dom082186 / query.php
Created October 8, 2015 07:56
WP Query
?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query(array(
'post_type' => 'business_partners',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
@dom082186
dom082186 / custom-css.css
Last active October 25, 2015 06:53
Custom CSS Framework
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css);.full-container{width:100%}.fixed-container{margin:0 auto;padding:0 15px}.column-container{font-size:0}.column{font-size:14px;padding:0 15px;vertical-align:top;display:inline-block}.xs-full{width:100%}.xs-one-half{width:50%}.xs-one-third{width:33.3333333333%}.xs-two-third{width:66.6666666667%}.xs-one-fourth{width:25%}.xs-two-fourth{width:50%}.xs-three-fourth{width:75%}.xs-one-fifth{width:20%}.xs-two-fifth{width:40%}.xs-three-fifth{width:60%}.xs-four-fifth{width:80%}.xs-one-sixth{width:16.6666666667%}.xs-two-sixth{width:33.3333333333%}.xs-three-sixth{width:50%}.xs-four-sixth{width:66.6666666667%}.xs-five-sixth{width:83.3333333333%}.xs-one-seventh{width:14.2857142857%}.xs-two-seventh{width:28.5714285714%}.xs-three-seventh{width:42.8571428571%}.xs-four-seventh{width:57.1428571429%}.xs-five-seventh{width:71.4285714286%}.xs-six-seventh{width:85.7142857143%}
<?php
/**
* Get all type posts
*
* @return void
* @author alispx
**/
function alispx_get_type_posts_data( $post_type = 'post' ) {
@abhisekp
abhisekp / FCC Bonfire - Where art thou Solutions.md
Last active February 1, 2017 22:16
Bonfire - Where art thou Solutions - FreeCodeCamp

Many of the solutions available around the internet for Bonfire: Where art thou are quite not right even if they pass the tests in FreeCodeCamp (FCC) because they don't adhere to the instructions completely.

  • Disclaimer: Please don't look into the solutions if you've not solved it yourself.

Bonfire Instruction:-

Make a function that looks through a list (first argument) and returns an array of all objects that have equivalent property values (second argument).


Here are two solutions that exactly adhere to the instructions given in the Bonfire Challenge.