Skip to content

Instantly share code, notes, and snippets.

@sammydigits
sammydigits / b.php
Created June 11, 2015 21:47
download an image using php
function save_image($inPath,$outPath)
{ //Download images from remote server
$in= fopen($inPath, "rb");
$out= fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
@sammydigits
sammydigits / a.php
Created June 11, 2015 21:31
Update parse object with PHP and cURL
<?php
$className = "TestObject";
$objectIdToEdit = "EtgV2fqx5z";
$url = 'https://api.parse.com/1/classes/' . $className . '/' . $objectIdToEdit;
$appId = 'yourApplicationIdHere';
$restKey = 'yourRestAPIKeyHere';
@sammydigits
sammydigits / backgrid-parse.js
Last active August 29, 2015 14:14
Backgrid + Parse.com Javascript SDK - with save back to parse.com
//load my Parse.com Class called "parts"
var Part = Parse.Object.extend("parts", {
//save the data back to parse.com when it changes
initialize: function() {
Parse.Object.prototype.initialize.apply(this,arguments); this.on("change", function (model,options) {
if (options && options.save === false) return;
model.save()
});
}
});
@sammydigits
sammydigits / hobbyking.js
Created December 31, 2014 16:33
hobbyking affiliate maker
var url = 'http://www.hobbyking.com/hobbyking/store/__55571__Quanum_Venture_FPV_QuadCopter_With_Power_System_ARF_Version_.html';
var numbers = url.replace(/[\D]/g, '');
console.log('http://www.hobbyking.com/hobbyking/store/uh_viewitem.asp?idproduct=' + numbers + '&aff=1588958');
@sammydigits
sammydigits / list-images.js
Created December 29, 2014 16:50
list all images on a page
var images = document.images;
for (var i=0; i<images.length; i++){
console.log(images[i].src);
}
@sammydigits
sammydigits / extract-filename-from-url.js
Created December 24, 2014 18:17
Exact filename from URL
function getFileName() {
//this gets the full url
var url = document.location.href;
//this removes the anchor at the end, if there is one
url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));
//this removes the query after the file name, if there is one
url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
//this removes everything before the last slash in the path
url = url.substring(url.lastIndexOf("/") + 1, url.length);
//return
@sammydigits
sammydigits / image-cycle.js
Created November 25, 2014 16:24
Super simple JQuery Image Cycle
//original: http://snook.ca/archives/javascript/simplest-jquery-slideshow
$(function(){
$('.fadein img:gt(0)').hide();
setInterval(function(){
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');},
3000);
});
@sammydigits
sammydigits / collapse.js
Created October 21, 2014 19:24
Collapse Bootstrap hamburger menu when clicked
$(document).on('click','.navbar-collapse.in',function(e) {
if( $(e.target).is('a') ) {
$(this).collapse('hide');
}
});
@sammydigits
sammydigits / getElementByClassName.js
Created August 20, 2014 18:38
getElementByClassName
if (!document.getElementsByClassName) {
document.getElementsByClassName = function(search) {
var d = document, elements, pattern, i, results = [];
if (d.querySelectorAll) { // IE8
return d.querySelectorAll("." + search);
}
if (d.evaluate) { // IE6, IE7
pattern = ".//*[contains(concat(' ', @class, ' '), ' " + search + " ')]";
elements = d.evaluate(pattern, d, null, 0, null);
while ((i = elements.iterateNext())) {
// node:
var moment = require('moment');
moment().add('days', 2).fromNow();
// 'in 2 days'
moment().subtract('days', 2).fromNow();
// '2 days ago'
moment('November 1977').fromNow()