Skip to content

Instantly share code, notes, and snippets.

View macabreb0b's full-sized avatar

a knee macabreb0b

View GitHub Profile
@macabreb0b
macabreb0b / dragon_boat.html
Last active August 29, 2015 14:08
render dragon boat seating chart with absolute positioning and hover effect
<html>
<head>
<style>
body * {
box-sizing: border-box;
}
.boat {
background-image: url(http://www.lively-dragon.com/Resources/Pictures/boat_seating.png);
background-size: 100% auto;
@macabreb0b
macabreb0b / jQuery.showCenter.js
Last active August 29, 2015 14:08
Click anywhere on your page to show crosshairs that reveal the vertical + horizontal midpoint.
$(function() {
$('body').one('click', function(event) {
var halfHeight = window.innerHeight / 2;
var halfWidth = window.innerWidth / 2;
var horizontalRule = $('<div style="width: 100%; height: ' + halfHeight + 'px; border: 0; border-bottom: thin solid blue; position: absolute; top:0;left:0"></div>');
var verticalRule = $('<div style="width: ' + halfWidth + 'px; height: 100%; border: 0; border-right: thin solid blue; position: absolute; top:0;left:0"></div>');
$('body').append(horizontalRule);
$('body').append(verticalRule);
})
@macabreb0b
macabreb0b / hashify_query_string.rb
Last active August 29, 2015 14:08
Rails-style Ruby method for turning a URL query string into a deeply-nested hash
require 'uri'
q1 = 'username=charlie&email=charlie@gmail'
q2 = 'user[username]=charlie&user[email]=charlie@gmail.com&user[password]=password'
q3 = 'user[address][street]=market&user[address][zipcode]=94103&user[email]=charlie@gmail.com'
puts URI.decode_www_form(q1).to_s
puts URI.decode_www_form(q2).to_s
puts URI.decode_www_form(q3).to_s
class Enumerable
def deep_dup
self.map do |*elements|
if element.is_a?(Enumerable)
element.deep_dup
else
elements.map do |element|
begin
duplicate = element.class.allocate
duplicate.send(:initialize_copy, element)
def subsets(array)
return [[]] if array.empty?
first = array.shift
subs = subsets(array)
other_subs = subs.map do |sub|
sub = sub + [first]
end
other_subs + subs
# for all numbers between 1 and a number,
# which can you add to the number infinitely
# (wrapping around when you hit the number)
# such that every number is stopped at once
def check_intervals(num)
best_intervals = []
current_max = 0
@macabreb0b
macabreb0b / .vimrc
Created December 10, 2014 18:01
dotfiles
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@macabreb0b
macabreb0b / linkedin_flirter.rb
Created October 31, 2014 00:21
A script for 'flirting' with users on LinkedIn by viewing their profiles
require 'selenium-webdriver'
username = 'your_username'
pword = 'your_pword'
browser = Selenium::WebDriver.for :firefox
browser.get 'https://linkedin.com'
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
@macabreb0b
macabreb0b / PhotoInput.jsx
Last active October 19, 2017 08:06
handle photo upload with React
import React, { Component } from 'react';
class PhotoInput extends Component {
constructor(props) {
super(props)
this.state = {
fileData: '',
}
@macabreb0b
macabreb0b / multlined_params.md
Last active November 10, 2017 01:09
Why you should multi-line parameter arguments

Parameters in "paragraph" style: 🚫 (BAD FOR DIFF)

Old:

def my_method(this, method, takes, a, bunch, 
              of, parameters):

New:

def my_method(this, method, now, takes,
 a, bunch, of, different, parameters):