Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
<script type="text/javascript">
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
document.cookie = cname + "=" + cvalue + ";" + "expires=" + d.toGMTString() + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = decodeURIComponent(document.cookie).split(';');
for(var i = 0; i < ca.length; i++) {
<?php
// only run this if the form has been submitted
if(isset($_POST['files'])){
// where are the PDFs stored on your server?
$source_directory = '/data/www/scripty/pdfs/';
$files = array();
// loop over the chosen PDFs
foreach($_POST['files'] as $key => $val){
// protect against malicious forms -- strip off anything besides a filename
$safe_val = array_pop(preg_split('/\//', $val, -1, PREG_SPLIT_NO_EMPTY));
// this first line, and the matching ending line, are inserted by Protaculous
document.observe('dom:loaded', function(evt){
// choose the parent box for the tabs, everything else is text within that box
var box = $('item1');
// choose the HTML tag that is used to create the tabs
var tabs = box.select('h3');
// choose the tags that are the content of the tab "bodies"
var bodies = box.select('p,ul,table,dl');
// CSS color (and you could do more styles, too) of the tabs
var tabStyle = 'background-color:#ccc';
I, [2016-11-15T22:52:24.906592 #21708] INFO -- : Processing by PaymentsController#create as HTML
I, [2016-11-15T22:52:24.906731 #21708] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"apYPpsVOzU4qiZeJoPX0g96rcT/Z56BuHZ3mV2+SQGWBENNlFuHQwbteEYMpxySxTLpMBUTKRWRrSN6VHmTg9g==", "payment"=>{"user_attributes"=>{"first_name"=>"Walter", "last_name"=>"Davis", "email"=>"waltd@mac.com", "address_1"=>"428 N. 13th Streetee", "address_2"=>"3 F", "address_3"=>"", "city"=>"Philadelphia", "state"=>"PA", "zip"=>"19123", "id"=>"1"}, "shipping_address_1"=>"428 N. 13th Streetee", "shipping_address_2"=>"3 F", "shipping_address_3"=>"", "shipping_city"=>"Philadelphia", "shipping_state"=>"PA", "shipping_zip"=>"19123", "stripe_token"=>"tok_19GFmuFeTGTinTk7FJhCvjUr"}}
D, [2016-11-15T22:52:24.908896 #21708] DEBUG -- : User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
I, [2016-11-15T22:52:24.916815 #21708] INFO -- : Completed 404 Not Found in 10ms (ActiveRecord:
http:// www. foo. bar /path/to/page.html?a=1&b=3 #some-thing
⬆︎ ⬆︎ ⬆︎ ⬆︎ ⬆︎ ⬆︎ ⬆︎
protocol subdomain domain top-level-domain pathname querystring anchor

Upload a file in Rails, parse it, then throw it away

You don't need Paperclip or Carrierwave or even an ActiveRecord model to manage file uploads in Rails if all you need to do is read the file in and extract data from it.

The Catalog class (referenced in the UploadController#create method) knows how to read a JSON file, translate and extract the data therein, and create or modify Book and Product records in the surrounding application.

By using the FileUtils.cp class method, we move the uploaded file into a known location at a known filename, so the Catalog (PORO) can do its work. The tempfile created by Rack during the upload is harvested as normal by garbage collection, but the copy we made is deleted manually after the parsing process is completed.

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4>My Header</h4>
</div>
<div class="modal-body">
<ul>
<li>
Something in a list.
</li>
<li>
<?php
// Autor: gallir@uib.es, header implementation for weak y strong
// HTTP validator according to RFC2616 of HTTP/1.1
// It's also compatible with HTTP/1.0 and
// take care of Netscape non-standard headers
// If more than 10800 secs have gone since last load
// it makes the client/cache to reload the page
// Call this function before doing anything else with databases or similar.
<?php
/**
* A field type for recording the date a form was submitted
*
* @package default
* @author Walter Davis
*/
class PerchFieldType_updated_at extends PerchAPI_FieldType
{
/**
@walterdavis
walterdavis / reflector.php
Created November 19, 2015 14:52
Form debugger
<?php
header('Content-type: text/html; charset=utf-8');
function clean($mxdInput){
//recursive function for multidimensional arrays
if(is_string($mxdInput)) return htmlspecialchars($mxdInput);
$out = array();
foreach($mxdInput as $k=>$v){
$out[$k] = clean($v);
}
return $out;