Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
jdjkelly / gist:1322626
Created October 28, 2011 16:01
Hubot Heroku Error
> node-expat@1.4.0 install /tmp/build_29jklg8iuk0q1/node_modules/hubot/node_modules/node-xmpp/node_modules/node-expat
> node-waf configure build
> node-expat@1.4.0 install /tmp/build_29jklg8iuk0q1/node_modules/hubot/node_modules/wobot/node_modules/node-xmpp/node_modules/node-expat
> node-waf configure build
npm ERR! error installing hubot-scripts@1.1.3 Error: Unsupported
npm ERR! error installing hubot-scripts@1.1.3 at checkEngine (/tmp/node-npm-77lk/lib/install.js:493:14)
npm ERR! error installing hubot-scripts@1.1.3 at Array.0 (/tmp/node-npm-77lk/node_modules/slide/lib/bind-actor.js:15:8)
@jdjkelly
jdjkelly / gist:1332714
Created November 2, 2011 02:41
Bing Spelling in JSON
var AppId = "D8E9ED76519B0D51D42D53256188D00E3A7BB2C2";
var requestStr = "http://api.bing.net/json.aspx?"
// Common request fields (required)
+ "AppId=" + AppId
+ "&Query=<?php the_search_query();?>"
+ "&Sources=Spell"
// Common request fields (optional)
+ "&Version=2.0"
@jdjkelly
jdjkelly / about_dice_project.rb
Created December 3, 2011 01:05
Solution for about_dice_project
class DiceSet
def initialize
dice = []
end
def roll(n)
@values = []
for i in (1..n)
@values << rand(6) + 1
@jdjkelly
jdjkelly / compare.rb
Created February 17, 2012 20:16
Comparing Two Arrays in Ruby
list1 = Array.new
list2 = Array.new
exist = File.open("exist.txt").each_line {|line| list1 << line.gsub(/\s+/, "")}
tocheck = File.open("tocheck.txt").each_line {|line| list2 << line.gsub(/\s+/, "")}
list2.each do |line|
if list1.include?(line)
File.open("output.txt", 'w') {|f| f.write(line) }
end
<progress min="0" max="100" value="0">0% complete</progress>
<script>
function upload(blobOrFile) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/server', true);
xhr.onload = function(e) { ... };
// Listen to the upload progress.
@jdjkelly
jdjkelly / gist:1986813
Created March 6, 2012 15:32
#wtfunction
function openFullSize(imageURL,imageTitle, pad){
var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
if( !imgWin ) { return true; } //popup blockers should not cause errors
imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
'var pad='+pad+';'+
'function resizeWinTo() {\n'+
'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
'var oH = document.images[0].height, oW = document.images[0].width;\n'+
'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
'window.doneAlready = true;\n'+ //for Safari and Opera
@jdjkelly
jdjkelly / gist:2013699
Created March 10, 2012 22:33
Local links preventify
$(document).on("click", "a:not([data-bypass])", function(evt) {
// Get the anchor href and protcol
var href = $(this).attr("href");
var protocol = this.protocol + "//";
// Ensure the protocol is not part of URL, meaning its relative.
if (href && href.slice(0, protocol.length) !== protocol && href.indexOf("javascript:") !== 0) {
// Stop the default event to ensure the link will not cause a page
// refresh.
evt.preventDefault();
@jdjkelly
jdjkelly / gist:2050551
Created March 16, 2012 15:31
301 Mania
Find.find('bouclair') do |f|
if f.match(/\.html\Z/)
file = File.open(f, "w")
file.puts('<html><head><meta http-equiv="Refresh" content="0; url=http://www.bouclair.com/" /></head><body><p>Our site has changed! Please follow <a href="http://www.bouclair.com/">this link</a>.</p></body></html>')
end
end
@jdjkelly
jdjkelly / gist:2147339
Created March 21, 2012 14:24
Bulk Ruby File Renaming
require 'fileutils'
filenames = Dir.glob("*.jpg")
filenames.each do |filename|
File.rename(filename, filename.gsub(/.jpg/, '') + "fr.jpg")
end
@jdjkelly
jdjkelly / SQLGroups.sql
Created March 27, 2012 20:07
Script to delete groups
delete from groups where group_id in (
select group_id from groups
where group_id not in (
select productgroup.groupid from groups
inner join productgroup ON groups.group_id = productgroup.groupid
)
)