Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / make_thumbs.php
Last active February 2, 2023 02:15
Convert .ai, .psd, .jpg, .png, .gif into thumbnails
<?php
/**
* Convert
* http://stackoverflow.com/questions/12516842/convert-psd-and-ai-to-png-jpg-with-imagick
* @param string $dir Directory to save to.
* @param string $tmpName The name to name the file excluding the extension.
* @param string $fileType
* @param string $size Large or small.
*/
@ivanhoe011
ivanhoe011 / flickr.js
Last active March 5, 2018 00:28
Load Flickr gallery
<html>
<head></head>
<body>
<div>
<div id="carousel">
<!--
<div>
<a href="images/dog-1.png" title="Dog" data-hover="Sandy the west highland terrier" data-toggle="lightbox" class="lightbox">
<img src="images/dog-1.png" alt="Dog" />
</a>
@ivanhoe011
ivanhoe011 / wp_reset_thumbs_sizes.php
Last active March 5, 2018 00:27
Resize all thumbs in WP
<?php
/**
* Resize all thumbs in WP when thumbnail settings are updated
*/
function update_thumbnails() {
set_time_limit(0); // can help if lot of images
$attachments = get_children( array('post_type' => 'attachment', 'post_mime_type' => 'image') );
@ivanhoe011
ivanhoe011 / wp_add_custom_sizes.php
Last active March 5, 2018 00:26
Add custom thumb sizes to Wordpress media dialog
<?php
// From http://wordpress.stackexchange.com/questions/76209/custom-image-size-with-new-media-manager-in-wordpress-3-5
/*
* Add custom thumb sizes to Wordpress media dialog
*/
function my_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
if ( !class_exists( 'HijackMe' ) ) {
class HijackMe {
public function hijack_menu($objects) {
/**
* If user isn't logged in, we return the link as normal
*/
if ( !is_user_logged_in() ) {
return $objects;
}
/**
<?php
if (preg_match('!!u', $string))
{
// this is utf-8
}
else
{
// definitely not utf-8
}
This gist contains two files for simple indexing of PDF files.
== requirements ==
First you need to install Solr (which requires a Java JDK): Download a tar or zipfile at http://www.apache.org/dyn/closer.cgi/lucene/solr/ and unpack it to a directory of your choice. Go into this directory and start solr running in jetty by:
$ cd example
$ java -jar start.jar
Then locate your browser to http://localhost:8983/solr/
$mock = Mockery::mock('SceneMongo');
$mock->shouldReceive('where')->with('visible', 1)->once()->andReturn($mock);
$mock->shouldReceive('where')->with('published_at', '<=', Mockery::type('int'))->once()->andReturn($mock);
$mock->shouldReceive('take')->with($limit)->once()->andReturn($mock);
$mock->shouldReceive('orderBy')->with('rating', 'DESC')->once()->andReturn($mock);
$mock->shouldReceive('get')->once()->andReturn($collection);
@ivanhoe011
ivanhoe011 / split.php
Created November 4, 2014 15:41
Split huge csv vertically
<?php
$split_on_column = 150; // on which column we split
$fp = fopen('big.csv', 'r'); // input
$f1 = fopen('out1.csv', 'w'); // output1
$f2 = fopen('out2.csv', 'w'); // output2
while ($row = fgetcsv($fp)) {