Skip to content

Instantly share code, notes, and snippets.

View Blackbam's full-sized avatar

David Stöckl Blackbam

View GitHub Profile
@jamiehs
jamiehs / gist:3364281
Created August 15, 2012 22:25
jQuery Array Intersect One Liner
// Find the common intersection between the arrays
a1=[1,2,3]
a2=[2,3,4,5]
$.map(a1,function(a){return $.inArray(a, a2) < 0 ? null : a;})
// http://stackoverflow.com/a/9401775/24559
@johnpolacek
johnpolacek / gist:3827270
Last active January 20, 2023 15:46
Prevent FOUC
<!-- Prevent FOUC (flash of unstyled content) - http://johnpolacek.com/2012/10/03/help-prevent-fouc/ -->
<style type="text/css">
.no-fouc {display: none;}
</style>
<script type="text/javascript">
document.documentElement.className = 'no-fouc';
// add to document ready: $('.no-fouc').removeClass('no-fouc');
</script>
@mathewbyrne
mathewbyrne / CsvResponse.php
Created March 21, 2013 22:54
A small Symfony 2 class for returning a response as a CSV file. Based on the Symfony JsonResponse class.
<?php
namespace Jb\AdminBundle\Http;
use Symfony\Component\HttpFoundation\Response;
class CsvResponse extends Response
{
protected $data;
@elidickinson
elidickinson / max_width_email.html
Created May 6, 2013 15:10
Email Template trick: max-width with outlook
<!--[if mso]>
<center>
<table><tr><td width="580">
<![endif]-->
<div style="max-width:580px; margin:0 auto;">
<p>This text will be centered and constrained to 580 pixels even on Outlook which does not support max-width CSS</p>
</div>
<!--[if mso]>
@maniaks
maniaks / add_setting_cpt.php
Created September 10, 2013 07:33
WordPress: Add Settings page to custom post type
<?php
//Example from Codex page : http://codex.wordpress.org/Function_Reference/add_submenu_page
//Add this in your functions.php file, or use it in your plugin
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'edit.php?post_type=book', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
@henriquemoody
henriquemoody / http-status-codes.php
Last active January 26, 2024 10:29
List of HTTP status codes in PHP
<?php
/**
* Content from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
*
* You may also want a list of unofficial codes:
*
* 103 => 'Checkpoint',
* 218 => 'This is fine', // Apache Web Server
* 419 => 'Page Expired', // Laravel Framework
@xeoncross
xeoncross / objectDump.php
Created October 3, 2014 16:16
Simple PHP object dump for those large objects with huge blobs of text or deep nested structures
<?php
/**
* Simple object dump for those large objects with huge blobs of text or deep nested structures
*/
function objectDump($object, $size = 70, $max = 5, $level = 0)
{
if($level > $max) return 'array(...MAX DEPTH REACHED...)';
$tab = str_repeat("\t", $level);
@litzinger
litzinger / create-magento-user.php
Created June 4, 2015 16:57
Create a Magento user via PHP script to get into admin area.
<?php
define( 'USERNAME', 'new.user' );
define( 'PASSWORD', 'password' );
define( 'FIRSTNAME', 'Excited' );
define( 'LASTNAME', 'Croc' );
define( 'EMAIL', 'new.user@magento.com' );
include_once( 'app/Mage.php' );
Mage::app( 'admin' );
try {
@mattclements
mattclements / function.php
Last active July 2, 2024 15:32
Wordpress Disable Comments (add to function.php)
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE