Skip to content

Instantly share code, notes, and snippets.

View nicksheffield's full-sized avatar

Nick Sheffield nicksheffield

View GitHub Profile
@nicksheffield
nicksheffield / script.js
Created December 2, 2012 20:02
Raphael.js - Variable Width Hexagon
function hexagon(x,y,w,h){
return paper.path(
'M' + (x+12) + ',' + y
+ 'L' + (x+12+w) + ',' + y
+ 'L' + (x+24+w) + ',' + (y+(h/2))
+ 'L' + (x+12+w) + ',' + (y+h)
+ 'L' + (x+12) + ',' + (y+h)
+ 'L' + x + ',' + (y+(h/2))
+ 'L' + (x+12) + ',' + y
)
@nicksheffield
nicksheffield / columns.less
Created February 27, 2013 05:33
Column calculator in LESS
.columns_6{
@page-width: 960px;
@columns: 6;
@gutter: 30px;
overflow: hidden;
[class*='grid_']{
display: block;
float: left;
@nicksheffield
nicksheffield / .htaccess
Last active December 21, 2015 16:59
Basic codeigniter .htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine on
# Don't use rewrite if its a real file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@nicksheffield
nicksheffield / function.js
Last active December 23, 2015 12:29
class in js 1
function myclass()
{
// property
this.name = 'John';
// method
this.greet = function()
{
console.log('Hello ' + this.name);
}
@nicksheffield
nicksheffield / bookmarklet.js
Created September 24, 2013 02:46
Google Font Tester
javascript:(function(){var font = prompt('What font?'), font_encoded = font.replace(' ','+');document.head.innerHTML += '<link rel="stylesheet" href="http://fonts.googleapis.com/css?family='+font_encoded+'">';document.body.innerHTML += '<style>*{font-family: "'+font+'" !important;}</style>';})();
@nicksheffield
nicksheffield / api.php
Last active December 27, 2015 03:19
PHP query building database class
<?php
// format
$db->method( $arg type, [$optional_arg type1|type2 default_val])
// methods
$db->select( $fields string )
@nicksheffield
nicksheffield / socket-in-angular.js
Created November 12, 2013 00:21
Socket.io service for Angular.js
app.factory('socket', function ($rootScope) {
var socket = io.connect();
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
<!-- Annoying -->
<label for="dothething">Do the thing?</label>
<input type="checkbox" id="dothething" />
<!-- Cool -->
<label for="dothething">
<input type="checkbox" id="dothething"> Do the thing?
</label>
@nicksheffield
nicksheffield / append.js
Last active December 28, 2015 15:38
Push a string into an array. If there is already an instance of the string in the array, append an appropriate number to the end of the string first.
function append(arr, string){
// if the string does exist in the array ..
if(arr.indexOf(string) != -1){
var n = 2;
var fin = false;
// .. loop indefinitely until we decide we have found a usable number.
while(!fin){
// if the string + the number doesn't exist
if(arr.indexOf(string+' ('+n+')') == -1){
@nicksheffield
nicksheffield / merge.js
Created November 19, 2013 00:03
Recursively merge two objects. Original objects will be overwritten by the ones from updates
function merge(original, updates){
for(var key in updates){
if(updates[key] instanceof Object && !(updates[key] instanceof Array)){
if(!original[key]) original[key] = {};
original[key] = merge (original[key], updates[key]);
}else{
original[key] = updates[key];
}