Skip to content

Instantly share code, notes, and snippets.

View rrrhys's full-sized avatar

Rhys Williams rrrhys

View GitHub Profile
@rrrhys
rrrhys / Create Screenshot of supplied CSS selector
Created April 20, 2012 07:01 — forked from n1k0/gist:1501173
PhantomJS: Capturing single dom elements as png files
var page = new WebPage(),
address, output, size;
var retval = {};
retval.result = "failed";
retval.messages = [];
//capture and captureSelector functions adapted from CasperJS - https://github.com/n1k0/casperjs
capture = function(targetFile, clipRect) {
try {
@rrrhys
rrrhys / quick HTML + Bootstrap + JS libs
Created August 11, 2014 11:17
Bootstrap + JQuery + Moment.js + Cookies.js from CDN template
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="initial-scale=1">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="/path/to/css/site.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Cookies.js/0.4.0/cookies.min.js"></script>
@rrrhys
rrrhys / Quick git add-commit-push-server pull.md
Last active August 29, 2015 14:11
Git shortcut bash file for windows - show modified files, ask for commit message, commit and push to remote.

How to:

Run ssh-keygen to generate a private/public keypair on your development machine.

Copy contents of id_rsa.pub to clipboard.

Paste the id_rsa.pub contents into ~/.ssh/authorized_keys on the server.

Change "111.222.333.444" to your remote server IP. (deploy.bat)

<?php // You need to add server side validation and better error handling here
$data = array();
if(isset($_FILES))
{
$error = false;
$files = array();
$uploaddir = './uploads/';
@rrrhys
rrrhys / gist:485b16b542608ce2054e
Created January 12, 2015 01:16
Quick and easy readable -> mysql UTC -> readable again
User chooses date and time in picker.
Post to server:
var mom = moment(date).utc().format("YYYY-MM-DD HH:mm:ss");
$.post("/endpoint", {time: mom}, function(obj){
if(typeof(obj) != "object"){
obj = $.parseJSON(obj);
}
@rrrhys
rrrhys / Client side function
Created June 16, 2015 03:44
Reset iOS badge to zero by installationId - parse.com and javascript
Parse.Cloud.run("resetBadge", {
installationId: installationId
});
@rrrhys
rrrhys / FormattedDbEntityValidationException.cs
Last active August 29, 2015 14:25
Wrap your Entities class.
public class FormattedDbEntityValidationException : Exception
{
public FormattedDbEntityValidationException(DbEntityValidationException innerException) :
base(null, innerException)
{
}
public override string Message
{
get
<modification>
<id>Tell Afterpay when shipped.</id>
<version>1.0.0</version>
<vqmver>2.5.1</vqmver>
<author>Rhys Williams</author>
<email>rwilliams@codeworkshop.com.au</email>
<website>www.codeworkshop.com.au</website>
<file name="catalog/model/checkout/order.php">
<operation>
select pm_cust.meta_value as user_id, sum(pm_disc.meta_value) as disc_total
from wp_postmeta pm_cust
inner join wp_postmeta pm_disc
on pm_disc.post_id = pm_cust.post_id and pm_disc.meta_key = '_cart_discount'
where pm_cust.meta_key = '_customer_user' and pm_cust.meta_value = 8;
@rrrhys
rrrhys / addTabsToText.js
Created August 24, 2018 05:54
Add tabstops to a body of text (React Native *does not* render tabs.
private repairBrokenTabs(text: string) {
let newLine = "\n";
let textLines = text.split(newLine);
let tabStop = 10;
let spaceString = Array(tabStop+1).join(" "); //
for (let l = 0; l < textLines.length; l++) {
let line = textLines[l];
while (line.indexOf("\t") > -1) {
let tabPos = line.indexOf("\t");
let modulo = tabStop - (tabPos % tabStop);