Skip to content

Instantly share code, notes, and snippets.

View Eunoia's full-sized avatar
🍍
bring the hustle

Evan R Eunoia

🍍
bring the hustle
View GitHub Profile
@Eunoia
Eunoia / static_site.rake
Created March 12, 2015 16:52
Turn rails into a static site.
namespace :static do
desc 'Generate static site in ./out/ directory'
task :generate do
Dir.mkdir 'out' unless File.exist? 'out'
Dir.chdir 'out' do
`wget -mnH http://localhost:3000/`
end
`rsync -ruv --exclude=.svn/ public/ out/`
end
@Eunoia
Eunoia / itemprops.js
Last active August 29, 2015 14:22
Get the itemprop after javascript blasts away fetched html, and og:tags
jQuery.get(document.location.href, function(html) {
itemprops = Array.prototype.slice.call(jQuery(html).find("[itemprop]"))
properties = itemprops.reduce(function(memo, curr) {
if (curr.tagName == "META") {
memo[curr.attributes.getNamedItem('itemprop').value] = curr.attributes.getNamedItem('content').value
} else {
memo[curr.attributes.getNamedItem('itemprop').value] = curr.innerText.trim();
}
return memo;
}, {})
@Eunoia
Eunoia / tell_the_time.js
Created August 5, 2015 18:51
What if your clock was off? Get the time from other servers date headers
var http = require('http'),
fs = require('fs'),
loadDomains, getTheTimeFromServerList, formatDateHeader;
loadDomains = new Promise(function (resolve, reject) {
var servers;
fs.readFile('hostnames.txt', 'utf8', function (err, data) {
if (err) {
reject('Unable to read hostnames.txt');
}
@Eunoia
Eunoia / LocationHistory.coffee
Created November 5, 2012 17:57
A class that logs locations using HTML5 geolocation
window.randomly = () -> (Math.round(Math.random())-0.5)
Number::toRadians = () -> @*2*Math.PI/360
class LocationHistory
constructor: (name = "Name", load = false, onUpdate) ->
if not navigator.geolocation
return "not supported"
@name = name
@times = []
@locations = []
@Eunoia
Eunoia / high_outliers
Created November 20, 2015 01:13
Uses DescriptiveStatistics to find outliers
def self.high_outliers(column)
values = pluck(column)
q1 = DescriptiveStatistics::Stats.new(select{|d| d.send(column)<values.median }.map{ |d| d.send(column)}).median
q3 = DescriptiveStatistics::Stats.new(select{|d| d.send(column)>values.median }.map{ |d| d.send(column)}).median
iqr = q3-q1
select { |d| d.send(column)>(q3 + 1.5 * iqr) }
end
@Eunoia
Eunoia / colors.rb
Last active December 10, 2015 11:08
class String
{
:reset => 0,
:bold => 1,
:dark => 2,
:underline => 4,
:blink => 5,
:negative => 7,
:black => 30,
:red => 31,
@Eunoia
Eunoia / word_hash.rb
Created January 3, 2013 01:19
My version of word_hash.rb I use for the classifier(https://github.com/cardmagic/classifier). It does not remove stop words, nor does it stem words. It also adds bi-grams to the bag of words(lines 21-28). This file lets the classifier look at the corpus more holistically, acknowledging that a corpus is not necessarily a bag of words, but that wo…
# Author:: Lucas Carlson (mailto:lucas@rufy.com)
# Copyright:: Copyright (c) 2005 Lucas Carlson
# License:: LGPL
# These are extensions to the String class to provide convenience
# methods for the Classifier package.
class String
# Removes common punctuation symbols, returning a new string.
# E.g.,
@Eunoia
Eunoia / pre-commit
Last active December 24, 2015 05:09 — forked from lsaffie/pre-commit
#!/bin/bash
# echo $
#This is good j
git diff --cached | grep -i "^\+[^#]*debugger" &&
# git diff --cached --name-only --diff-filter=ACM
exit 1
# Pre commit hook that prevents FORBIDDEN code from being commited.
# Add unwanted code to the FORBIDDEN array as necessary
@Eunoia
Eunoia / unclaimed.rb
Created October 5, 2013 21:06
Just a little class to programmatically look up unclaimed property for californians.
require 'nokogiri'
require 'open-uri'
require 'pry'
require 'net/http'
require 'net/https'
class UnclaimedProperty
attr_accessor :lname, :fname, :middle, :city
attr_reader :results, :more_results_than_shown
def initialize(options)
?>
<li class="one-third first single-item create-board" data-price="000000" data-category="!000000" data-source="000000" data-purchased="100000000000">
<a onClick='iframe_open("/popups/popup-add-item.php?name=<?php echo rawurlencode($project) . '&pnumber=' . $pnumber; ?>", "480", "200", "no")'>
<img src="images/plus-sign-large.png" alt="Add New Sum Board">
<p>Add New Item</p>
</a>
</li>
<?php