Skip to content

Instantly share code, notes, and snippets.

View jefferyf's full-sized avatar

Jeff Miller jefferyf

  • Minneapolis, MN
View GitHub Profile
@jefferyf
jefferyf / mcd_converter.rb
Created June 20, 2012 20:21
Monthly Consumption Details Conversion
ConsumptionDetail.find_in_batches(:batch_size => 500, :start => 208771) do |cd_batch|
cd_batch.each{ |cd|
cd.save(:validate => false); puts "ID: #{cd.id.to_s} ~ BUILDING NAME: #{cd.energy_source.property.name}"
}
end
@jefferyf
jefferyf / squeel_where.rb
Created August 31, 2012 15:11
Conditional where clause generation with squeel
# Class method on Intakes model
def self.find_for_report(options={})
joins{intake_grant}.
where do
conditions = {}
conditions[pending.eq] = false
conditions[intake_grant_id] = options[:grant_id] unless options[:grant_id].blank?
conditions[intake_date.gt] = options[:from] unless options[:from].blank?
conditions[intake_date.lt] = options[:to] unless options[:to].blank?
var casper = require("casper").create();
var url = "https://github.com/search?langOverride=VimL&language=&q=vimrc&repo=&type=Repositories&start_value=" + casper.cli.get(0);
var repoLinks = [];
var fileLinks = [];
function getRepoLinks() {
var links = [];
$("div.results .result h2 a").each(function(i,el){
links.push(el.href);
});
var casper = require('casper').create();
casper.start();
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)');
casper.viewport(1024, 768);
casper.thenOpen('http://jsbin.com/ifuma#noedit', function() {
this.capture('test.png');
@jefferyf
jefferyf / Howto.md
Created February 11, 2013 02:41 — forked from n1k0/Howto.md

Put test1.js and test2.js into a tests/ directory, then run the suite:

$ casperjs test tests/ --pre=pre.js --includes=inc.js --post=post.js
Test file: /Users/nperriault/tmp/pre-inc/pre.js                                 
Hey, I'm executed before the suite.
Test file: /Users/nperriault/tmp/pre-inc/tests/test1.js                         
# this is test 1
Hi, I've been included.
PASS Subject is strictly true
/*
* Takes provided URL passed as argument and make screenshots of this page with several viewport sizes.
* These viewport sizes are arbitrary, taken from iPhone & iPad specs, modify the array as needed
*
* Usage:
* $ casperjs screenshots.js http://example.com
*/
var casper = require("casper").create();
@jefferyf
jefferyf / getHits.groovy
Last active December 15, 2015 04:59
Get info re mt hit
import com.reachlocal.grails.sales.Advertiser
import com.reachlocal.grails.sales.AdvertiserConnection
import com.reachlocal.grails.amt.*
import com.reachlocal.grails.question.*
String comment = "****************************************************"
def advertisers = Advertiser.findAllByLastAnalyzedIsNotNull([max: 20, sort: "id", order: "desc", offset: 0])
advertisers.each{advertiser->
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import groovyx.net.http.RESTClient
import com.reachlocal.grails.mozenda.MozendaAgentRun
import com.reachlocal.grails.mozenda.MozendaInputProperty
def http = new HTTPBuilder('http://localhost:8080/')
def html
@jefferyf
jefferyf / cleanHITs.groovy
Last active December 15, 2015 13:08
Clean up HITs missing from my local database
import java.math.RoundingMode
import com.reachlocal.grails.amt.MechanicalTurkHIT
def mtService = ctx.mechanicalTurkService
//Determine the number of pages over which we need to iterate.
def node = mtService.searchHITs('CreationTime', 'Descending', 100, 1)
println "searchHITs NumResults: ${node.NumResults}, PageNumber: ${node.PageNumber}, TotalNumResults: ${node.TotalNumResults}"
def numPages = (node.TotalNumResults.toInteger()/100).setScale(0, RoundingMode.UP)
//MT won't let us get more than 100 HITs per request, so iterate through the pages.
@jefferyf
jefferyf / getMissingHITs.groovy
Last active December 15, 2015 14:09
Gets Missing MT HIT data
import java.math.RoundingMode
import com.reachlocal.grails.amt.MechanicalTurkHIT
def mtService = ctx.mechanicalTurkService
//Determine the number of pages over which we need to iterate.
def node = mtService.searchHITs('CreationTime', 'Descending', 100, 1)
def numPages = (node.TotalNumResults.toInteger()/100).setScale(0, RoundingMode.UP)
println "searchHITs NumResults: ${node.NumResults}, PageNumber: ${node.PageNumber}, TotalNumResults: ${node.TotalNumResults}, TotalPages: ${numPages}"
long sd = System.currentTimeMillis()