Skip to content

Instantly share code, notes, and snippets.

@meglio
meglio / cors.nginxconf
Last active March 18, 2016 05:46 — forked from pauloricardomg/cors.nginxconf
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
#
# Acts as a nginx HTTP proxy server
# enabling CORS only to domains matched by regex
#
server {
listen 80;
server_name corsproxy.mydomain.com;
location / {
proxy_redirect off;
@meglio
meglio / gist:7a63c1c243e3c118ae86
Created July 8, 2015 04:33
Discourse Top 5 Last Month
{% for topic in data.topic_list.topics|slice(0,5) %}
<a target="_blank" href="https://meta.discourse.org/t/{{topic.slug}}/{{topic.id}}">
{{topic.title}}
</a>
{% endfor %}
<?php
$s = 'Iñtërnâtiônàlizætiøn-р X';
$pdo = new PDO('mysql:host=localhost;dbname=fa', '...', '...', [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET CHARACTER SET utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$res = $pdo->query('SELECT label FROM connectors WHERE id = 18', PDO::FETCH_COLUMN, 0);
$sDB = $res->fetchColumn();
@meglio
meglio / BackgroundProcess.php
Created March 2, 2015 12:19
Run any command in background from PHP
<?php
namespace _\sys;
use RuntimeException;
class BackgroundProcess
{
/**
* Theory:
@meglio
meglio / example-nginx-website
Created February 18, 2015 12:24
Nginx website virtual host example
# WWW HTTP(S) -> non-WWW
server {
listen 80;
#listen 443 ssl;
server_name www.EXAMPLE.COM;
return 301 $scheme://EXAMPLE.COM$request_uri;
#ssl_certificate /home/USER/.ssl/ssl-unified.crt;
#ssl_certificate_key /home/USER/.ssl/ssl.key;
}
@meglio
meglio / blank_server.sh
Last active August 29, 2015 14:15
Blank Server
# Add locale to the list of generated locales
echo ru_RU.UTF-8 UTF-8 >> /var/lib/locales/supported.d/local
# Regenerate list (it will invoke locale-gen...)
dpkg-reconfigure locales
# Set default passwords for mysql
# TODO: Setting blank password does not work (?)
debconf-set-selections <<< 'mysql-server mysql-server/root_password password'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password'
@meglio
meglio / wp-nginx
Created February 14, 2015 03:25
wp-nginx
# WWW HTTP -> non-WWW
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
@meglio
meglio / wp-single
Created February 14, 2015 03:24
wp-single
# WordPress single blog rules.
# Designed to be included in any server {} block.
index index.php;
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
@meglio
meglio / wp-restrictions
Created February 14, 2015 03:23
wp-restrictions
# Global restrictions configuration file.
# Designed to be included in any server {} block.
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
@meglio
meglio / ajax-items.js
Created August 28, 2014 14:17
JS component to allow for inline edition of CRM items in admin panels through inline dialogs.
function AjaxItems($container, config) {
var defaultOpts = {
textNoItems: "Не знайдено",
removalActionClass: "actionRemove",
removalDialog: function(el) { return confirm('Видалити?') },
showNoItems: function($container, message) {
$container.empty().append( $div().text(message) )
},
// If you want item removal to be handled, add an element with class .actionRemove (or another specified in removalActionClass option)
itemDom: function(el) {