Skip to content

Instantly share code, notes, and snippets.

@p-m-p
p-m-p / Adaptor example HTML
Created November 5, 2014 19:38
How to implement the HTML for a 3D rotation effect
<div class="slider-viewport"><!-- works as a viewport for the 3D transitions -->
<div class="content-box"><!-- the 3D box -->
<figure><!-- slide -->
<img src="img/slide-1.png">
<figcaption>This is slide one's description</figcaption>
</figure>
<figure><!-- slide -->
<img src="img/slide-2.png">
<figcaption>This is slide two's description</figcaption>
</figure>
{
"item": [
{"text": "Number one", "value": 23},
[12,42,55,31,74]
]
}
@p-m-p
p-m-p / gist:2015743
Created March 11, 2012 09:38
Metaprogramming with method_missing
class SystemUser
def initialize(first_name, last_name)
@credentials = {
:first_name => first_name,
:last_name => last_name
}
end
def method_missing(m, *args)
@p-m-p
p-m-p / gist:2015739
Created March 11, 2012 09:35
execute around with blocks
File.open('demo.txt', 'a') do |f|
f.puts 'In and out, nice and clean'
end
# File is closed
@p-m-p
p-m-p / gist:2015736
Created March 11, 2012 09:34
Optional syntax for hashes and methods
class SystemUser
def initialize(first_name, last_name)
@credentials = {
:first_name => first_name,
:last_name => last_name
}
end
def set_credentials(creds)
@p-m-p
p-m-p / gist:2015731
Created March 11, 2012 09:31
Defining operators for classes
class AccessGroup
attr_accessor :name
def initialize(name)
@name, @members = name, []
end
# add the user to the group using the common shift operator
# used by collections
@p-m-p
p-m-p / index_operator_issue_cf8.cfm
Created September 8, 2011 20:44
CF8 array index increment operator issue
<cfscript>
path = []; // cached path out to root node
ended = false; // ended = true once we reach the root
nodeID = 1; // leaf node db id --would have been passed in
level = 1; // levels up from leaf nodeID
// very simplified version of the code
while (!ended) {
parentDept = getParentDept(nodeID);
if (parentDept) {
@p-m-p
p-m-p / captures.cfm
Created May 16, 2011 22:02
Capture groups in Java
<cfscript>
// read in log file contents
accessLog = fileRead("/var/log/apache2/access.log");
// set up our regular expression with groups
regex = 'GET\s([^\s]+)\sHTTP\/\d.\d"\s404\s[0-9]+\s"([^"]+)';
// Using rematch we lose our groups
matches = REMatch(regex, accessLog);
writeDump(matches);
@p-m-p
p-m-p / stickysidebar.jquery.js
Created May 7, 2011 21:12
StickySidebar jQuery plugin
(function($){
var settings = {
speed: 350 //animation duration
, easing: "linear" //use easing plugin for more options
, padding: 10
, constrain: false
}
, $window = $(window)
, stickyboxes = []
@p-m-p
p-m-p / widget.php
Created April 2, 2011 09:58
Example usage of the API_cache object
<?php
require 'api_cache/API_cache.php';
$cache_file = 'twitter.json';
$api_call = 'http://search.twitter.com/search.json?q=nodeJS&lang=en';
$cache_for = 5; // cache results for five minutes
$api_cache = new API_cache ($api_call, $cache_for, $cache_file);
if (!$res = $api_cache->get_api_cache())