Skip to content

Instantly share code, notes, and snippets.

@kimchaily
kimchaily / simpleUpload.js
Created June 7, 2017 09:31
Simple Upload of a Blob/File created in Code
function simpleUpload( destination, filename, filetype, data ) {
var formData = new FormData();
var blob = new Blob([data], { type: filetype });
formData.append('file', blob, filename);
var request = new XMLHttpRequest();
request.open('POST', destination);
request.send(formData);
};
@kimchaily
kimchaily / FormValidationPolyfill.js
Last active February 18, 2016 09:48
JS Form Validation Polyfill with modernizr
/*! modernizr 3.3.1 (Custom Build) | MIT *
* http://modernizr.com/download/?-formvalidation-setclasses !*/
!function(e,n,t){function o(e,n){return typeof e===n}function a(){var e,n,t,a,i,s,r;for(var l in f)if(f.hasOwnProperty(l)){if(e=[],n=f[l],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;t<n.options.aliases.length;t++)e.push(n.options.aliases[t].toLowerCase());for(a=o(n.fn,"function")?n.fn():n.fn,i=0;i<e.length;i++)s=e[i],r=s.split("."),1===r.length?Modernizr[r[0]]=a:(!Modernizr[r[0]]||Modernizr[r[0]]instanceof Boolean||(Modernizr[r[0]]=new Boolean(Modernizr[r[0]])),Modernizr[r[0]][r[1]]=a),d.push((a?"":"no-")+r.join("-"))}}function i(e){var n=u.className,t=Modernizr._config.classPrefix||"";if(c&&(n=n.baseVal),Modernizr._config.enableJSClass){var o=new RegExp("(^|\\s)"+t+"no-js(\\s|$)");n=n.replace(o,"$1"+t+"js$2")}Modernizr._config.enableClasses&&(n+=" "+t+e.join(" "+t),c?u.className.baseVal=n:u.className=n)}function s(){return"function"!=typeof n.cr
@kimchaily
kimchaily / alfred2-openNewChromeWindow
Created April 16, 2015 15:46
Alfred workflow. Open a new window in Chrome and if URL given, then go to that URL
on alfred_script(q)
if not (q starts with "http://")
set q to "http://" & q
end if
tell application "/Applications/Google Chrome.app"
make new window
set URL of active tab of window 1 to q
end tell
end alfred_script
#!/bin/bash
function help() {
echo "batch-rename allows you to rename a bulk of filenames with RegEx"
echo "usage: batch-rename -r [Search] [Replace]"
echo "param -r: do effective renaming instead of just showing what would be done"
}
function dummyRename() {
echo "simulate renaming \"$1\" to \"$2\""
for file in * ; do echo "simulate: $file ->" "`echo $file | sed -E "s/$1/$2/g"`" ; done
@kimchaily
kimchaily / gist:8874760
Created February 8, 2014 00:30
Batch renaming in Terminal (e.g. bash) using RegEx
// Example: replace every capital letter with 'abc', only changing m4a-files
for file in *.m4a ; do mv -vf "$file" "`echo $file | sed -E 's/[A-Z]/abc/g'`" ; done
// Sublime-Text snippet:
<snippet>
<content><![CDATA[
for file in *.${1:m4a} ; do mv -vf "\$file" "`echo \$file | sed -E 's/${2:[A-Z]}/${0:abc}/g'`" ; done
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>rename</tabTrigger>