Skip to content

Instantly share code, notes, and snippets.

View mflisikowski's full-sized avatar
🎯
Focusing

Mateusz Flisikowski mflisikowski

🎯
Focusing
View GitHub Profile
@mflisikowski
mflisikowski / iframe.html
Created September 25, 2015 05:03 — forked from jamenlyndon/iframe.html
Resize iframe height to fit content (works cross domain)
<script type='text/javascript' src="js/jquery.min.js"></script>
<script type='text/javascript'>
// Size the parent iFrame
function iframeResize() {
var height = $('body').outerHeight(); // IMPORTANT: If body's height is set to 100% with CSS this will not work.
parent.postMessage("resize::"+height,"*");
}
$(document).ready(function() {
// Resize iframe
@mflisikowski
mflisikowski / debounce.js
Created September 12, 2017 15:04 — forked from tcase360/debounce.js
Debounce function in ES6
const debounce = (fn, time) => {
let timeout;
return function() {
const functionCall = () => fn.apply(this, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}
}
@mflisikowski
mflisikowski / nginx.conf
Created May 30, 2018 15:51 — forked from chrisallenlane/nginx.conf
This is an nginx configuration that does the following: - Implements a RESTful API using CORS between `example.com` and `api.example.com` - Uses SSL - Reverse-proxies SSL traffic from port 443 to a NodeJS application running on port 8000 Adapted from this page, with thanks to the original author: http://enable-cors.org/server_nginx.html
# Configure the reverse-proxy on port 443
server {
# general configs
keepalive_timeout 30;
listen 127.0.0.1:443 ssl;
server_name api.example.com;
# ssl configs
ssl_certificate /path/to/api.crt;
ssl_certificate_key /path/to/api.key;
@mflisikowski
mflisikowski / .localenv
Created November 9, 2018 19:13 — forked from amlwwalker/.localenv
Configuration I have been using for connecting to MongoDB Atlas
ENVIRONMENT=development
HOSTNAME=localhost:4000
MONGODB_DB=reactnodenew
MONGODB_HOST=localhost
MONGODB_PASS=
MONGODB_PORT=27017
MONGODB_QUERIES=
MONGODB_SSL=FALSE
MONGODB_USER=
NODE_ENV=development
@mflisikowski
mflisikowski / easing.js
Created March 31, 2020 22:42 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: t => t,
// accelerating from zero velocity
easeInQuad: t => t*t,
// decelerating to zero velocity
@mflisikowski
mflisikowski / debounce.js
Created May 12, 2020 05:40 — forked from beaucharman/debounce.js
An ES6 implementation of the debounce function. "Debouncing enforces that a function not be called again until a certain amount of time has passed without it being called. As in 'execute this function only if 100 milliseconds have passed without it being called.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debounc…
function debounce(callback, wait, immediate = false) {
let timeout = null
return function() {
const callNow = immediate && !timeout
const next = () => callback.apply(this, arguments)
clearTimeout(timeout)
timeout = setTimeout(next, wait)
@mflisikowski
mflisikowski / throttle.js
Created May 12, 2020 05:46 — forked from beaucharman/throttle.js
An ES6 implementation of the throttle function. "Throttling enforces a maximum number of times a function can be called over time. As in 'execute this function at most once every 100 milliseconds.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debouncing/)
function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return function() {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, arguments)
timeout = null
}
@mflisikowski
mflisikowski / metabox-page.php
Created July 20, 2020 21:56 — forked from nandomoreirame/metabox-page.php
add custom metabox per page
<?php
function theme_metabox_per_page() {
global $pagenow;
if ( $pagenow == 'post.php' ) {
$page_id = ( $_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['post_ID'] ) ? $_POST['post_ID'] : $_GET['post'];
if ( $page_id ) {
$page_slug = get_post_field( 'post_name', $page_id );
@mflisikowski
mflisikowski / custom-fields.php
Created July 20, 2020 21:56 — forked from nandomoreirame/custom-fields.php
Add custom post meta to WordPress REST API
<?php
function get_custom_post_meta_cb($object, $field_name, $request) {
return get_post_meta( $object['id'], $field_name, true );
}
function get_custom_post_meta_cb_the_content($object, $field_name, $request) {
return apply_filters( 'the_content', get_post_meta( $object['id'], $field_name, true ) );
}
<?php
add_action('rest_api_init', function () {
register_rest_route( 'contact/v1', 'send', [
'methods' => 'POST',
'callback' => 'api_send_contact_form'
]);
});
function api_send_contact_form( $request ) {