Skip to content

Instantly share code, notes, and snippets.

@robmint
robmint / get x and y from a UIEvent in iOS
Created August 26, 2010 23:39
get x and y from a UIEvent in iOS
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// touches is a NSSet - we get the first in the set
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSLog(@"x=%f y=%f",touchPoint.x, touchPoint.y);
}
@robmint
robmint / Apache wildcard virtual host config
Created February 26, 2012 23:04
Many virtual hosts under one domain
NameVirtualHost *
<VirtualHost *>
ServerName fruit.com
DocumentRoot /www/html/htdocs/fruitsite/docroot
</VirtualHost>
<VirtualHost *>
ServerName www.apple.com
ServerAlias www.banana.com www.cherry.com
@robmint
robmint / gist:3120600
Created July 16, 2012 04:44
add sections to the wordpress customize panel
<?php
require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
class WP_Customize_Palette_Control extends WP_Customize_Image_Control {
public $type = 'palette';
public $removed = '';
public $context;
@robmint
robmint / gist:4753401
Last active May 18, 2020 10:48
Basic linux framebuffer graphics setup
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <stdbool.h>
#include <linux/input.h>
@robmint
robmint / hashList.js
Last active December 7, 2015 00:42
iterating through hash of lists in javascript
data = {
subject: ['Medical Science', 'Philosophy'],
year: ['2015', '2013']
};
for (key in data) {
if (data.hasOwnProperty(key) && data[key] instanceof Array) {
list = data[key];
list.forEach(function (value) {
console.log(key + " : " + value);
@robmint
robmint / popArray.js
Last active December 8, 2015 01:26
Adds lists to an object, pushing to a list if a known key is specified.
// works well with querystring.stringify to produce GET parameters
function objectArrayPush(data, key, value) {
if (typeof data[key] != 'undefined' && data[key] instanceof Array) {
// EXISTS: pushing onto list
data[key].push(value);
} else {
// CREATING: pushing onto list
data[key] = [];
data[key].push(value);
@robmint
robmint / list_of_lists.hbs
Created January 6, 2016 01:42
Iterating over a list of lists in a Handlebars template
<!--- json input data:
index: [
[
{divider: true, text: "A", url: ""},
{text: "ACCTG 371", url: "", count:23},
{text: "ACCTG 371", url: "", count:23},
{text: "ACCTG 371", url: "", count:23},
{text: "ACCTG 371", url: "", count:23},
{text: "ACCTG 371", url: "", count:23}
],
@robmint
robmint / pagination.php
Last active October 29, 2019 11:14
Pagination like flickr, digg, github - the standard pagination pattern
<?php
// based on the work of Jason Coleman
// http://www.strangerstudios.com/blog/2006/07/paginate-your-site-like-digg/
/* The pagination function simply spits out a data structure
that you can render any way you like.
See also the javascript version for node:
https://gist.github.com/robmint/4651cf1c6f336e663dba
*/
@robmint
robmint / pagination.js
Last active January 12, 2016 00:49
standard pagination pattern for node
extend = require(extend);
/* Creates an array of items representing the pagination navigation.
You can then pass this to your template engine eg handlebars
Also see the PHP version:
https://gist.github.com/robmint/e4b037aba1687195524c
Based on the work of Jason Coleman
http://www.strangerstudios.com/blog/2006/07/paginate-your-site-like-digg/
*/
@robmint
robmint / url-test.js
Created February 11, 2016 00:53
Huffman compression of URLs in node.js
// just a test to see if compressing url-encoded json looks/works any better
var strofa = require("strofa");
cl = function(obj) { console.dir(obj, {depth: null, colors: true}); };
var string = '{"subjectonly_keyword":["ACCTG 713"]}';
cl(string);
cl(encodeURIComponent(string));