Skip to content

Instantly share code, notes, and snippets.

View adriandmitroca's full-sized avatar

Adrian Dmitroca adriandmitroca

View GitHub Profile
@adriandmitroca
adriandmitroca / example.com
Created May 16, 2016 12:37
nginx example configuration with OPCache's workaround
server {
listen 80;
listen 443 ssl http2;
server_name example.com www.example.com;
root /home/deploy/example.com/current/public;
error_log /home/deploy/example.com/logs/error.log;
access_log /home/deploy/example.com/logs/access.log;
@adriandmitroca
adriandmitroca / .htaccess
Created September 8, 2016 11:28
Basic Laravel's htaccess configuration
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
AddHandler application/x-httpd-php70 .php
@adriandmitroca
adriandmitroca / knapsack.py
Last active April 2, 2017 10:19
Comparison of 3 alghoritms for Knapsack problem
#!/usr/bin/python
# -*- coding: utf-8 -*-
from itertools import combinations
import random
import time
import timeit
"""
Porównaj różne algorytmy rozwiązujące dyskretny problem plecakowy.
@adriandmitroca
adriandmitroca / functions.php
Last active May 12, 2017 18:32
WooCommerce - Hide shipping methods for specific shipping classes / Add support to hide shipping methods for specified shipping classes to WooCommerce
<?php
add_filter('woocommerce_package_rates', 'hide_shipping_methods', 10, 2);
/**
* Hide specific shipping methods for packages with negative cost set.
* There is no need to hard code any IDs of shipping classes or products if you can just set negative value
* on the back-end and then delete these methods on the fly.
*
* @param $rates
@adriandmitroca
adriandmitroca / form-handler.php
Last active May 31, 2017 07:29
Snippet for quick contact form handling with vanilla PHP/JS + $.ajax
<?php
$subject = 'Temat wiadomości';
$recipient = 'recipient@example.com';
$output = [
'success' => 'Dziękujemy za wiadomość.',
'error' => 'Coś poszło nie tak. Spróbuj ponownie.',
];
@adriandmitroca
adriandmitroca / app.js
Created December 18, 2018 11:33
Debounce done right in Vue.js
import debounce from 'lodash/debounce';
export default {
data() {
return {
loading: false,
query: null,
};
},
watch: {
@adriandmitroca
adriandmitroca / post-share.php
Last active February 17, 2020 13:43
WordPress - Social Share Example
<ul>
<li><a href="https://www.facebook.com/sharer/sharer.php?u=<?= rawurlencode(get_permalink()) ?>" target="_blank" rel="noopener noreferrer">Facebook</a></li>
<li><a href="https://twitter.com/intent/tweet?status=<?= rawurlencode(get_the_title() . ' ' . get_permalink()) ?>" target="_blank" rel="noopener noreferrer">Twitter</a></li>
<li><a href="mailto:?subject=<?= rawurlencode(get_the_title()) ?>&body=<?= rawurlencode(get_permalink()) ?>">Email</a></li>
</ul>
@adriandmitroca
adriandmitroca / config.yml
Last active February 20, 2020 10:32
CircleCI Deployment Recipe with assets building (Yarn with cache support) & git-ftp
version: 2
jobs:
build:
docker:
- image: circleci/php:7.2-node-browsers
working_directory: ~/repo
steps:
- checkout
@adriandmitroca
adriandmitroca / Icon.vue
Last active July 6, 2020 15:46
SVGs in Vue.js loaded inline via HTTP with simple object cache. This is handy if you don't necessarily have single page app with full access to Webpack and want some quick and efficient way to use SVGs inline (eg. Laravel Mix). No 3rd party libraries or loaders required.
<template>
<html-fragment :html="icon" />
</template>
<script>
import axios from "axios"
export default {
props: {
name: String,
@adriandmitroca
adriandmitroca / app.js
Created July 17, 2019 12:30
Lottie, automatically fixing SVG scaling issue on Internet Explorer 11
const lottieIeFixer = (el, perspective = 'width') => {
if (!window.navigator.userAgent.includes('Windows') && !window.navigator.userAgent.includes('rv:11.0')) {
return;
}
const $el = $(el);
const width = $el.width();
const height = $el.height();
const $svg = $el.find('svg');