Skip to content

Instantly share code, notes, and snippets.

@rantastic
rantastic / document_read.js
Created March 21, 2013 17:26
JS: jquery document ready function
$(function() {
// jquery
});
@rantastic
rantastic / spin.js
Created March 21, 2013 17:40
JS: spin
!function(t,e,i){var o=["webkit","Moz","ms","O"],r={},n;function a(t,i){var o=e.createElement(t||"div"),r;for(r in i)o[r]=i[r];return o}function s(t){for(var e=1,i=arguments.length;e<i;e++)t.appendChild(arguments[e]);return t}var f=function(){var t=a("style",{type:"text/css"});s(e.getElementsByTagName("head")[0],t);return t.sheet||t.styleSheet}();function l(t,e,i,o){var a=["opacity",e,~~(t*100),i,o].join("-"),s=.01+i/o*100,l=Math.max(1-(1-t)/e*(100-s),t),p=n.substring(0,n.indexOf("Animation")).toLowerCase(),u=p&&"-"+p+"-"||"";if(!r[a]){f.insertRule("@"+u+"keyframes "+a+"{"+"0%{opacity:"+l+"}"+s+"%{opacity:"+t+"}"+(s+.01)+"%{opacity:1}"+(s+e)%100+"%{opacity:"+t+"}"+"100%{opacity:"+l+"}"+"}",f.cssRules.length);r[a]=1}return a}function p(t,e){var r=t.style,n,a;if(r[e]!==i)return e;e=e.charAt(0).toUpperCase()+e.slice(1);for(a=0;a<o.length;a++){n=o[a]+e;if(r[n]!==i)return n}}function u(t,e){for(var i in e)t.style[p(t,i)||i]=e[i];return t}function c(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var
@rantastic
rantastic / form_submit.js
Created March 21, 2013 17:46
JS: Form submit
$('form').on('click','[trigger="formSubmit"]',function(){
var button = $(this);
var form = button.closest('form');
button.html('&nbsp;');
button.spin('small');
button.attr('disabled','disabled');
form.find('input,select,textarea').closest('.control-group').removeClass('error');
form.find('input,select,textarea').next().empty();
@rantastic
rantastic / post_validate.php
Created March 21, 2013 18:36
PHP: Post validate
foreach($_POST as $key => $value){
switch($key){
case $key == 'email':
if ($value == ''){
$data['error'][] = array($key,'Enter your email');
}
else{
if (!filter_var($value, FILTER_VALIDATE_EMAIL)){
@rantastic
rantastic / pdo_select.php
Created March 21, 2013 18:55
PHP: PDO select statement return array
$stmt = $db->prepare('SELECT * FROM tablename WHERE colname = ?');
$stmt->execute(array($variable));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if($stmt->rowCount()>0){
foreach($results as $result){
}
}
@rantastic
rantastic / pdo_insert_single.php
Created March 21, 2013 20:34
PHP: PDO insert single
$stmt = $db->prepare("INSERT INTO tablename (var1, var2, var3) VALUES (?,?,?)");
$stmt->execute(array($var1,$var2,$var3));
if($stmt->rowCount()>0){
}
@rantastic
rantastic / pdo_update_single.php
Created March 21, 2013 20:37
PHP: PDO update single
$stmt = $db->prepare("UPDATE tablename SET tableRow = ?, tableRow2 = ? WHERE tableRow3 = ?");
$stmt->execute(array($var1,$var2,$var3));
if($stmt->rowCount()>0){
}
@rantastic
rantastic / bootstrap_modal.html
Created March 26, 2013 21:39
HTML: Bootstrap modal
<div id="registerModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
@rantastic
rantastic / jquery_post.js
Created April 3, 2013 15:13
JS: jquery post
$.post('ajax/PAGE', postData,
function(data){
},
'json');
@rantastic
rantastic / simple_curl.php
Created April 11, 2013 15:23
PHP: Simple CURL
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$a = curl_exec($ch);
$youtubeJSON=json_decode($a,true);