Skip to content

Instantly share code, notes, and snippets.

@laverboy
laverboy / gist:6068615
Created July 24, 2013 07:16
Potential iPhone home button fix (or recalibrate)
View gist:6068615
  1. Open any application eg messages

  2. Press and hold the power button until the slide to shutdown bar appears.

  3. Release power button

  4. Press and hold Home button with normal pressure and wait until screen returns to icon screen

  5. Enjoy your functioning home button!!!

@laverboy
laverboy / createTemplateFromObject.js
Last active December 27, 2015 16:39
Really simple javascript templating. Input is html string and data object.
View createTemplateFromObject.js
function createTemplateFromObject(template, data) {
var t = '';
// For each item in the object, make the necessary replacement
for (key in data) {
console.log(key, data);
reg = new RegExp('{{' + key + '}}', 'ig');
t = (t || template).replace(reg, data[key]);
}
@laverboy
laverboy / image-replacement.js
Last active November 27, 2016 06:11
Javascript Image Replacement technique in Wordpress
View image-replacement.js
// --------------------------------
// load images from their data-src
// --------------------------------
// - pure javascript
for (var i = document.querySelectorAll('[data-src]').length - 1; i >= 0; i--) {
var image = document.querySelectorAll('[data-src]')[i];
image.src = image.getAttribute('data-src');
};
// - jQuery
$('[data-src]').each(function (){
@laverboy
laverboy / gist:b86485e1806d3cba6a8f
Last active August 29, 2015 14:02
Update Wordpress with new server name in sql
View gist:b86485e1806d3cba6a8f
update table_name set option_value = replace(option_value,"oldurl.com","newurl.com");
@laverboy
laverboy / dyn_vhosts.conf
Created October 7, 2014 18:19
Dynamic Vhosts
View dyn_vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
UseCanonicalName Off
ServerName vhosts.local.reasondigital.com
ServerAlias *
VirtualDocumentRoot /Users/mlaver/Projects/%1/htdocs/
Options All ExecCGI FollowSymLinks +Includes
</VirtualHost>
@laverboy
laverboy / config.php
Created June 8, 2015 08:04
Dot Notation Accessor
View config.php
<?php
return [
'version' => '1.0.0',
'table' => 'table_name',
'info' => [
'item' => [
'name' => 'cherry',
'value' => 'pick'
]
@laverboy
laverboy / DashboardWidget.php
Last active August 29, 2015 14:27
Singleton Pattern for functions.php
View DashboardWidget.php
<?php namespace CharityPress\Functions;
/**
* Enqueue scripts and styles.
*/
class DashboardWidget extends Singleton {
//required function
public function init() {
add_action( 'wp_dashboard_setup', [ $this, 'intro_widget' ] );
@laverboy
laverboy / LogUse.php
Last active May 16, 2023 10:34
A simple, static, logging singleton class
View LogUse.php
<?php
Log::info("something really interesting happened", ['extra' => 'information', 'about' => 'anything' ]);
View ws_and_json.scala
import scala.util.parsing.json.JSON
import scalaj.http.Http
// Assumes a list of objects. If response i only as single object, the last
// .asInstanceOf[Seq[Map[String, Any]]] could be changed to .asInstanceOf[Map[String, Any]]
def getService(serviceURL: String, serviceAuthToken: String): Seq[Map[String, Any]] = {
JSON.parseFull(
Http(serviceURL)
.timeout(connTimeoutMs = 600000, readTimeoutMs = 10000)
@laverboy
laverboy / logback.xml
Created March 17, 2017 12:22
Simplified logback settings for test
View logback.xml
<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>
<!-- Suppress logback complaining about multiple logback.xml files -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- We use short exception stack trace logging to limit output for travis. -->