Skip to content

Instantly share code, notes, and snippets.

View IQAndreas's full-sized avatar

Andreas Renberg IQAndreas

View GitHub Profile
# Taken from http://code.activestate.com/recipes/577058-query-yesno/
# with some personal modifications
def yes_no(question, default=True):
"""Ask a yes/no question via raw_input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
// `bigRect.mouseX` can be replaced by `stage.mouseX - bigRect.x`
var ratioX:Number = bigRect.mouseX / bigRect.width;
var ratioY:Number = bigRect.mouseY / bigRect.height;
// This is the x and y location inside of the small rectangle which should line up with the above point
var offsetX:Number = ratioX * smallRect.width;
var offsetY:Number = ratioY * smallRect.height;
smallRect.x = bigRect.x + (ratioX * bigRect.width) - offsetX;
smallRect.y = bigRect.y + (ratioY * bigRect.height) - offsetY;
post_id date name link submit
contact
2012-03-13 04:11
Lorem ispum
Submit Comment

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel mollis massa, ac volutpat velit. Phasellus sed feugiat velit. Nullam accumsan, quam vel bibendum vulputate, justo elit consequat nunc, sed fringilla nibh nunc vel odio. Phasellus ut nunc libero. Aliquam diam purus, mattis sed ornare eu, volutpat eget orci. Sed at dolor a odio facilisis pretium et et arcu. Mauris cursus quam et convallis cursus. Maecenas sagittis tempus nisl, consectetur luctus elit viverra sed. Proin fringilla elit augue, ac viverra dui auctor eget. Proin porttitor volutpat augue ac tincidunt. Ut at posuere turpis. Sed vel accumsan metus. Vestibulum consequat at metus vitae vulputate. Aenean enim urna, hendrerit sed ultricies sed, tempor eget enim. Pellentesque consequat euismod rutrum. Aenean vitae eros vel ante vestibulum pulvinar.

**Vestibulum mattis adipiscing felis, vel adipiscing nulla gravida v

var vowels = ['a', 'e', 'i', 'o', 'u'];
'abcdefghijklmnopqrstuvwxyz'.replace(/[a-z]/g, function (l) {
if (l === 'z') return 'A';
l = String.fromCharCode(l.charCodeAt(0) + 1);
return (vowel.indexOf(l) != -1) ? l.toUpperCase() : l;
}); //bcdEfghIjklmnOpqrstUvwxyzA
@IQAndreas
IQAndreas / slug-version-1.rb
Created October 19, 2013 22:48
Slug function where there is no trailing slash (note that `contact.html` and `contact/index.html` return the same value)
# Sample output:
# URL: /contact.html SLUG: /contact
# URL: /contact.htm SLUG: /contact
# URL: contact.html SLUG: contact # The output only starts with a forward-slash if the input does...
# URL: /contact/index.html SLUG: /contact
# URL: /index.html SLUG: /
# URL: index.html SLUG: / # ... except here.
# URL: /dummy/.html SLUG: /dummy # Just don't use stupid page names like this
# URL: /.html SLUG: / # Again, I'm just too lazy to account for stupid cases
# URL: /funny/images/cats.html SLUG: /funny/images/cats
@IQAndreas
IQAndreas / slug-version-2.rb
Created October 19, 2013 22:51
Slug function where there IS a trailing slash (note the difference between `contact.html` and `contact/index.html`)
# Sample output:
# URL: /contact.html SLUG: /contact
# URL: /contact.htm SLUG: /contact
# URL: contact.html SLUG: contact # The output only starts with a forward-slash if the input does (always)
# URL: /contact/index.html SLUG: /contact/ # <-- Here is the major difference between this and the other version
# URL: /index.html SLUG: /
# URL: index.html SLUG: (empty string)
# URL: /dummy/.html SLUG: /dummy/ # Just don't use stupid page names like this
# URL: /.html SLUG: / # Again, I'm just too lazy to account for stupid cases
# URL: /funny/images/cats.html SLUG: /funny/images/cats/
@IQAndreas
IQAndreas / hour12.js
Created November 16, 2013 21:12
Gets the hour value and the "time period" (AM/PM) based on the 24-hour you pass in (this code is VERY verbose for clarity)
var h = new Date().getHours();
if (h == 0)
{
period = am
hours = 12
}
else if (h > 0 && h < 12)
{
period = am
try:
state = "initializing"
read_configs()
state = "downloading"
files = get_files()
state = "importing"
import_files(files)
state = "complete"
@IQAndreas
IQAndreas / MouseEvent.js
Created April 9, 2014 04:39
I hate passing strings as event strings. Only problem is, rather than throw an error, misspelled constants in JavaScript return `undefined`. Damn this weak language!
MouseEvent.CLICK = 'click';
MouseEvent.CONTEXT_MENU = 'contextmenu';
MouseEvent.DOUBLE_CLICK = 'dblclick';
MouseEvent.MOUSE_DOWN = 'mousedown';
MouseEvent.MOUSE_ENTER = 'mouseenter';
MouseEvent.MOUSE_LEAVE = 'mouseleave';
MouseEvent.MOUSE_MOVE = 'mousemove';
MouseEvent.MOUSE_OUT = 'mouseout';
MouseEvent.MOUSE_OVER = 'mouseover';
MouseEvent.MOUSE_UP = 'mouseup';
// I have to create an entirely new Rectangle class from scratch, because 'Rect' doesn't actually have a
// constructor or any other way of creating your own rectangles.
// http://stackoverflow.com/questions/22953073/does-rect-have-a-constructor-function
function Rectangle(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}