Skip to content

Instantly share code, notes, and snippets.

View rjcorwin's full-sized avatar

R.J. (Steinert) Corwin rjcorwin

View GitHub Profile
<?php
$words = Array("cat", "dog", "fish", "rabbit");
foreach($words as $word) {
file_put_contents("$word.mp3", fopen("https://ssl.gstatic.com/dictionary/static/sounds/de/0/$word.mp3", 'r'));
}
?>
window.URL = window.URL || window.webkitURL
var blob = new Blob(['body { color: red; }'], {type: 'text/css'})
var link = document.createElement('a')
link.innerHTML = 'Click to download style.css.'
link.href = window.URL.createObjectURL(blob)
// Name the Blob so it doesn't result in a gibberish name
link.download = 'style.css'
// Append the download link to the body
document.body.appendChild(link)
// Optionally, if you want this to immediately download and don't care about the download link, run the click method
@rjcorwin
rjcorwin / backbone-models-for-couchdb-boiler-plate.js
Last active December 18, 2015 03:19
The bare minimum you must do to get Backbone.js Models to work with CouchDB.
var SomeModelClass = Backbone.Model.extend({
idAttribute: "_id",
url: function() {
if (_.has(this, 'id')) {
var url = (_.has(this.toJSON(), '_rev'))
? this.server + '/' + this.db + '/' + this.id + '?rev=' + this.get('_rev') // For UPDATE and DELETE
: this.server + '/' + this.db + '/' + this.id // For READ
}
@rjcorwin
rjcorwin / PouchDB-Cordova-Test-Logcat.log
Created July 9, 2013 18:40
Output from running various tests from https://github.com/rjsteinert/PouchDB-Tests-for-Apache-Cordova-PhoneGap on an emulator running Android 4.0.3
# Test.ReplicateToDbThenOpenDb()
07-10 01:16:15.217: I/Web Console(6543): DEVICE READY 14 at file:///android_asset/www/index.html:23
07-10 01:16:15.317: D/SurfaceTextureClient(6543): dispatchSetBuffersGeometry1!
07-10 01:16:15.317: D/SurfaceTextureClient(6543): dispatchSetBuffersGeometry2!
07-10 01:16:16.197: I/SqliteDatabaseCpp(6543): sqlite returned: error code = 1, msg = no such table: CacheGroups, db=/data/data/com.Test.TestPouch/databases/webview.db
07-10 01:16:16.197: I/SqliteDatabaseCpp(6543): sqlite returned: error code = 1, msg = no such table: Caches, db=/data/data/com.Test.TestPouch/databases/webview.db
07-10 01:16:16.197: I/SqliteDatabaseCpp(6543): sqlite returned: error code = 1, msg = no such table: Origins, db=/data/data/com.Test.TestPouch/databases/webview.db
07-10 01:16:16.197: I/SqliteDatabaseCpp(6543): sqlite returned: error code = 1, msg = no such table: DeletedCacheResources, db=/data/data/com.Test.TestPouch/databases/webview.db
07-10 01:16:16.507: D/CordovaLog(6543): DroidGap: onExceed
@rjcorwin
rjcorwin / phonegap_download_example.html
Created July 10, 2013 14:36 — forked from nathanpc/phonegap_download_example.html
Warning, I don't think this works.
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- Android
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">-->
<!-- iPad/iPhone specific css below, add after your main css >
@rjcorwin
rjcorwin / open-pdf-from-pouchdb.js
Created July 26, 2013 20:28
Load a PDF from PouchDB using the PDF.js Viewer. This code would go somewhere around line 2930 in web/viewer.js replacing the code that opens the PDF for Firefox and non B2G browsers. Example (note the parameters): http://test.local:5984/mount/_design/app/PDF-JS-Pouch-Viewer/web/viewer.html?db=testfiles&docId=helloworld&file=helloworld.pdf
if(params.db && params.docId && params.file) {
Pouch(params.db, function(err, db) {
db.getAttachment(params.docId, params.file, function(err, res) {
var file = window.URL.createObjectURL(res)
//#if (FIREFOX || MOZCENTRAL)
//if (FirefoxCom.requestSync('getLoadingType') == 'passive') {
// PDFView.setTitleUsingUrl(file);
// PDFView.initPassiveLoading();
@rjcorwin
rjcorwin / open-pdf-with-width-of-screen.js
Last active December 20, 2015 07:19
From pdf.js/examples/helloworld/hello.js, modify it to open display the page specified at the width of browser. We do this by looking at the width of the PDF's page and the width of the window and then setting the scale of the page's viewport accordingly (see line 5).
PDFJS.getDocument(url).then(function(pdf) {
// Using promise to fetch the page
pdf.getPage(1).then(function(page) {
// Scale the PDF to the width of the window
var scale = window.innerWidth / page.view[2]
var viewport = page.getViewport(scale);
//
// Prepare canvas using PDF page dimensions
//
@rjcorwin
rjcorwin / vars-assigned-this-act-like-pointers.js
Created July 30, 2013 20:56
A variable with a "this" assigned to it will act like a pointer in Javascript.
var x = {
value: 1,
change: function() {
var that = this
that.value++
var foo = 1
var bar = foo
bar++
alert(foo) // alerts 1
}
<?php
$codeToCountry = array(
"af" =>"Afghanistan",
"ax" =>"Aland Islands",
"al" =>"Albania",
"dz" =>"Algeria",
"as" =>"American Samoa",
"ad" =>"Andorra",
@rjcorwin
rjcorwin / parallax-background-scroll-using-jquery.js
Created August 18, 2013 07:13
Dead simple parallax scroll an element's background using jQuery. Inspired by http://parascroll.wwwtyro.net/
window.onscroll = function() {
var speed = 3.0;
$("#some-container").css("background-position",(window.pageXOffset / speed) + "px " + (window.pageYOffset / speed) + "px");
// Scroll the background faster instead of slower
// $("#some-container").css("background-position",(-window.pageXOffset / speed) + "px " + (-window.pageYOffset / speed) + "px");
}