Skip to content

Instantly share code, notes, and snippets.

View coleww's full-sized avatar

Cole Willsea coleww

  • (=^.^=)
  • Berkeley, CA
View GitHub Profile
@coleww
coleww / gist:79c9764593ff00cefde1
Created June 2, 2014 23:42
no login social network
https://panopticlick.eff.org/
instead of username/pass concatenate all user agent data together and hash it. users with identical (and i mean identical) machines/environments will have the same "account".
ALTERNATIVELY: use the uniqueness of this string to institute some kind of limit. a game you can only play once. etc. (play, building things until you get cashed, new player steps in, etc.)
OH ALSO: a game where you control like 100 copies of yourself. multiple man: the game?
@coleww
coleww / gist:9561fb22a4cf7888a3a5
Last active August 29, 2015 14:02
render html in sql
CREATE OR REPLACE FUNCTION render (table_name string, action string, ids string)
RETURNS string AS $rendered_template$
BEGIN
declare
temp_temp string;
rendered_template string;
SELECT
db_views.template AS template, db_views.variables AS variables
FROM
db_views
@coleww
coleww / gist:9691d59a1cae37a3f8ee
Created June 7, 2014 16:41
Turn a github readme into a presentation
//removes everything except the readme document from the page and adds some pads.
$("body").html($("#readme").html()).css({padding: "50px"})
fields = {'#title': 'blah', '.body': 'bla blah', '#date': '1/27/14 etc.', '.option-thing': 'checked'};
submit = '.submit';
var formify = function(fields, submit){
fields.keys.forEach(function(selector){
if(fields[selector] === 'checked' || fields[selector] === 'radio') $(selector).prop('checked', 'checked');
if(fields[selector] === 'click') $(selector).click();
$(selector).val(fields[selector]);
});
@coleww
coleww / gist:cfaea55b92570ea9fced
Last active August 29, 2015 14:03
using fibonacci in a web app
def set_amount
fibs = [0, 1]
self.amount = ([10, 7, 5, 3, 2, 1].map { |amt| [amt] * (fibs[0], fibs[1] = fibs[1], fibs[0] + fibs[1])[0]}.flatten).sample
end
#i really wish i could find a way to not have to declare the fibs array...
#this is for like a raffle type thing.
@coleww
coleww / gist:93b14f1d519f71561346
Last active August 29, 2015 14:03
my_each spec
class Array
def my_each
end
def my_map
end
def my_inject
end
end
@coleww
coleww / gist:75029e1243284b9374be
Last active August 29, 2015 14:03
like every
var likes = document.getElementsByClassName('UFILikeLink');
var comment_likes = [];
var post_likes = [];
for(var i = 0; i<likes.length; i++){
if (likes[i].getAttribute('title') === 'Like this') {
post_likes.push(likes[i]);
} else if (likes[i].getAttribute('title') === 'Like this comment') {
comment_likes.push(likes[i]);
}
@coleww
coleww / gist:2e0a11eabe28a836f497
Last active August 29, 2015 14:03
voiding javascript
<h1> no script console </h1>
<h2> can it be haxed? </h2>
<script>
var recursive_void = function (thing){
for(var x in thing){
console.log(x);
console.log("BONK")
if (typeOf(thing[x]) === "Object") {
@coleww
coleww / gist:55cea96ff08dd30af611
Created July 18, 2014 14:11
weighted shuffle in ruby.
things.sort_by do |thing|
-((thing.created_at.to_f / Time.now.to_f) * rand)
end