Skip to content

Instantly share code, notes, and snippets.

View ajace's full-sized avatar

Ace Atienza ajace

  • Cainkade
  • New York, NY
View GitHub Profile
function dom(name, attributes) {
var node = document.createElement(name);
if (attributes) {
forEachIn(attributes, function(name, value) {
setNodeAttribute(node, name, value);
});
}
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child == "string")
@ajace
ajace / walkTheDom.js
Created September 16, 2013 18:45
Crockford's WalkTheDom ex: var root = document.getElementById('div'); walkTheDOM(root, function(node) { console.log( node.nodeName ); });
function walkTheDOM(node, func) {
func(node);
node = node.firstChild;
while (node) {
walkTheDOM(node, func);
node = node.nextSibling;
}
}
@ajace
ajace / mac_osx_setup.sh
Last active December 25, 2015 19:39
Setup for a new mac osx. Web Development
#!/bin/bash
# zsh
# uninstall_oh_my_zsh
curl -L github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
# http://bahoom.com/hyperswitch
defaults write com.apple.Finder AppleShowAllFiles TRUE
killall Finder
@ajace
ajace / initial_setup.sh
Last active December 26, 2015 17:49
Ubuntu 14.10 web development setup
#!/bin/sh
# chmod +x initial_setup.sh
# sudo ./initial_setup.sh
sudo apt-get install -y \
curl \
vim \
git \
alacarte \
@ajace
ajace / array_keys_i.php
Created December 18, 2013 20:42
PHP: array keys search for insensitive input
function array_keys_i($array, $str){
$results = array();
foreach($array as $key => $value) {
if(stristr($str,$value)) {
$results[] = $key;
}
}
if(empty($results)) {
@ajace
ajace / $.ajax.form.submit.js
Created January 15, 2014 19:22
ajax form submittal using jquery; useful inside of iframes since .submit() doesn't work
var url = location.origin;
var form = $('').serialize();
$.ajax({
url: url,
type: 'post',
dataType: 'json',
data: form,
}).done(function(data){
console.log("success");
@ajace
ajace / getQueryVariable.js
Created February 21, 2014 16:55
from CSS-Tricks. grab a query value in the uri
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
@ajace
ajace / pinterest
Created October 14, 2014 14:34
Custom Pinterest Button with auto url and auto media
<!-- credit: http://www.brandaiddesignco.com/insights/add-a-custom-pinterest-pin-it-button-to-your-website/ -->
<a href='javascript:void((function()%7Bvar%20e=document.createElement(&apos;script&apos;);e.setAttribute(&apos;type&apos;,&apos;text/javascript&apos;);e.setAttribute(&apos;charset&apos;,&apos;UTF-8&apos;);e.setAttribute(&apos;src&apos;,&apos;http://assets.pinterest.com/js/pinmarklet.js?r=&apos;+Math.random()*99999999);document.body.appendChild(e)%7D)());'><img src='http://www.brandaiddesignco.com/insights/PinIt.png'/></a>
@ajace
ajace / tweet
Created October 14, 2014 16:27
Twitter Tweet Popup
<script>
function tweetIt(event) {
window.twttr=window.twttr||{};
var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0,F=document,E;
if(C>A){G=Math.round((C/2)-(A/2))}
var fullLink = 'http://twitter.com/share?url=' + encodeURIComponent(document.URL) + '&text=' + encodeURIComponent(document.title);
window.twttr.shareWin=window.open(fullLink,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
E=F.createElement('script');
E.src='https://platform.twitter.com/widgets.js';
F.getElementsByTagName('head')[0].appendChild(E);
@ajace
ajace / jquery-ui-date-validation.js
Last active August 29, 2015 14:21
jquery-ui-date-validation
function(dateText) {
try {
// US format
$.datepicker.parseDate('mm/dd/yy', dateText);
} catch (e) {
alert(e);
// alert user
};
}