Skip to content

Instantly share code, notes, and snippets.

@jclapp23
jclapp23 / kata
Last active August 29, 2015 14:13
_ _ _ _ _ _ _
|_| | _||_||_ |_ ||_| _|
_| ||_ | _||_| ||_| _|
912456783
---------------------------------------------------------------------
package kata;
@jclapp23
jclapp23 / Phantom JS html scraper
Created March 30, 2015 15:46
Phantom JS html scraper
var page = require('webpage').create();
page.onError = function (msg, trace) {
phantom.exit();
};
page.onAlert = function( msg ) {
@jclapp23
jclapp23 / Phantom JS html scraper
Last active August 29, 2015 14:18
Phantom JS html scraper
var page = require('webpage').create();
page.onError = function (msg, trace) {
phantom.exit();
};
page.onAlert = function( msg ) {
@jclapp23
jclapp23 / Phantom JS Html Scraper - Output to XML object
Last active August 29, 2015 14:18
Phantom JS Html Scraper - Output to XML object
public function pullXmlObjBlogExample($siteUrl,$cssSelector){
//create configuration object containing jquery selector and target site url to pass to the phantom script
$config = array(
"selector"=>$cssSelector,
"url"=>$siteUrl
);
//read in the base phantom script and create a copy of it so we don't mess with the original base script
@jclapp23
jclapp23 / Phantom JS scrape populations by state
Last active August 29, 2015 14:18
Phantom JS scrape populations by state
private function scrapePopulationsByState(){
$cssSelector = "table.sk_popcharttable";
$siteUrl = "http://www.ipl.org/div/stateknow/popchart.html";
$tableXmlObject = pullXmlObjBlogExample($siteUrl,$cssSelector);
$cnt = 0;
@jclapp23
jclapp23 / Phantom JS final output from PHP
Created March 30, 2015 15:58
Phantom JS final output from PHP
California has a population of 37,253,956
Texas has a population of 25,145,561
New York has a population of 19,378,102
Florida has a population of 18,801,310
Illinois has a population of 12,830,632
Pennsylvania has a population of 12,702,379
Ohio has a population of 11,536,504
Michigan has a population of 9,883,640
Georgia has a population of 9,687,653
North Carolina has a population of 9,535,483
if($scheduleString){
$formattedSchedule = json_decode($scheduleString);
could be shortened to this because json_decode will return false if string doesnt exist or is garbage
if($formattedSchedule = json_decode($scheduleString)){
public function onPreSetData(FormEvent $event)
{
$form = $event->getForm();
$form->add('plainOasPassword', 'text',
array(
'required'=>false,
'label'=>"Oas Password",
'attr' => array('placeholder'=>'Existing value is set, but obscured for security purposes')
@jclapp23
jclapp23 / template-general.php
Created July 25, 2013 13:30
WP_Cal_Demo # 1
<?php
// Get days with posts
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
AND post_type = 'post' AND post_status = 'publish'
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
if ( $dayswithposts ) {
foreach ( (array) $dayswithposts as $daywith ) {
$daywithpost[] = $daywith[0];
@jclapp23
jclapp23 / gist:6079671
Created July 25, 2013 13:32
WP_Cal_Demo # 2
<?php
// Get days with posts
$dayswithposts = $wpdb->get_results("SELECT (FROM_UNIXTIME(`wp_postmeta`.`meta_value`,'%d')) as dom ,
`wp_postmeta`.`post_id` , `wp_posts`.`guid` , `wp_posts`.`post_title`
FROM $wpdb->postmeta
LEFT JOIN `wp_posts` ON `wp_postmeta`.`post_id` = `wp_posts`.`ID`
WHERE `wp_postmeta`.`meta_key` = 'event_startdate'
AND `wp_posts`.`post_status` = 'publish'
AND `wp_postmeta`.`meta_value` >= UNIX_TIMESTAMP( '{$thisyear}-{$thismonth}-01 00:00:00' )