Skip to content

Instantly share code, notes, and snippets.

View jessehattabaugh's full-sized avatar
🤠
pew pew

Jesse Hattabaugh jessehattabaugh

🤠
pew pew
View GitHub Profile
function get_analyze_terms(){
printp("total:",storage.site.terms)
storage.terms.sort(lastAnalyzed).limit(40).forEach(function(t){
t.volume = (100 / storage.site.count) * t.count
if(t.volume > 0.1) t.relevant = false
else if(t.volume < 0.008) t.relevant = false
else t.relevant = true
storage.interests.filter({term:t}).forEach(function(i){
i.volume = (100 / i.user.count) * i.count
i.difference = i.volume - t.volume
function cron_analyze_users(){
var subject = storage.users.sort(lastAnalyzed).first()
var interests = []
storage.interests.filter({user:subject,relevant:true}).forEach(function(i){
interests[i.term.string] = i.difference
})
var analyzed = []
storage.relations.filter({subject:subject}).forEach(function(r){
function parseDate(date){
//Tue, 12 Aug 2008 20:36:35 -0700
var d = Date.parse(date.replace(/,/g,"").substring(4,25))
if(d) return d
else {
dlog.error("couldn't parse date (",d,") from (",date,")")
return new Date()
}
}
function niceDate(date) {
if(typeof date == 'object') {
if(Date.today().compareTo(date) == -1) return 'today'
else if(Date.today().add({days:-1}).compareTo(date) == -1) return 'yesterday'
else return date.toString('MM/dd/yy')
} else return '02/24/82'
}
function niceTime(date) {
if(typeof date == 'object') {
if(date > (1).minutes().ago())
function cron_refresh(){
storage.feeds.sort(stale).limit(5).forEach(function(feed){
var loadedFeed = loadFeed(feed.url)
// here would be a good place to update the rest of the feed's fields in case they've changed
var entries = loadedFeed.entries
var n=0
for(var i=0; i<entries.length; i++){
var someEntry = storage.entries.filter({feed:feed, title:entries[i].title}).first()
if(!someEntry) {
var published = parseDate(entries[i].publishedDate)
function cron_analyze_entries(){
const limit = 500
var terms = []
var interests = []
var count = 0
storage.entries.filter({analyzed:false}).sort().forEach(function(e){
text = (e.title+' '+e.content).replace(/<[a-zA-Z\/][^>]*>/g, ' ').toLowerCase().clean()
words = text.match(/\b\w{3,}\b/g)
if((count += words.length) > limit) return false
if(words){
function cron_analyze_users(){
// get a user that needs to be analyzed
var subject = storage.users.sort(lastAnalyzed).first()
// make a hash of their interests and the difference between the volume of
// the term for the user and the volume of the term on the whole site.
var interests = []
storage.interests.filter({user:subject,relevant:true}).forEach(function(i){
interests[i.term.string] = i.difference
})
function cron_analyze_users(){
var subject = storage.users.sortBy('analyzed').first()
print(subject.name)
if(!subject.interests)
subject.relevant = false
else {
storage.users.filter({relevant:true}).sortBy('active').forEach(function(object){
if(object.email != subject.email){
relation = storage.relations.filter({subject:subject, object:object}).first()
@jessehattabaugh
jessehattabaugh / gist:113645
Created May 18, 2009 18:02
Facebook Connect get_status() demonstration
if(FB.Connect.get_status() == FB.ConnectState.userNotLoggedIn){
alert('user is not logged in');
} else {
alert('user is logged in');
}
if(FB.Connect.get_status() == FB.ConnectState.appNotAuthorized){
alert('app is not authorized');
} else {
alert('app is authorized');
}
<html><body>
<h1>Find a Unique Username</h1>
<p>With a limit of 15 characters</p>
<form method="get">
<label>First Name <input name="first_name" /></label>
<label>Last Name <input name="last_name" /></label>
<label>Quit after <input name="end" value="111" /></label>