Skip to content

Instantly share code, notes, and snippets.

View IQAndreas's full-sized avatar

Andreas Renberg IQAndreas

View GitHub Profile
@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 / 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
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
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

// `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;
# 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).
@IQAndreas
IQAndreas / profile
Last active December 22, 2015 20:19 — forked from wolever/profile
# prompt examples:
# [3 jobs master] ~/code/myproject/foo
# [1 job my-branch] ~/code/bar/
# ~
# Very, very fast, only requiring a couple of fork()s (and no forking at all to determine the current git branch)
if [[ "$USER" == "root" ]]
then
export PS1="\e[1;31m\]\u \[\e[1;33m\]\w\[\e[0m\] ";
else
@IQAndreas
IQAndreas / helloWorld.java
Last active December 21, 2015 08:09
Want to run Shell/Bash commands but are sick and tired of how sickeningly untyped they are? Introducing JavaSH!
#!/bin/javash
# Both Bash and Java comments supported (not a feature, I was just too lazy to force one or the other)
// Some basic commands are included
echo("Hello world!");
// Others, you have to manually run
String currentDir = run("pwd");
echo(currentDir);
@IQAndreas
IQAndreas / test
Last active December 21, 2015 07:49
Running this script in terminal (via just a standard `./test`) will execute the script located in `/home/andreas/custom-script` passing this file as the first argument
#!/home/andreas/custom-script
This will not be treated as code, but if executed in shell,
the script located in `/home/andreas/custom-script`
will run and be executed, passing the path to this
file as the first parameter.
@IQAndreas
IQAndreas / BlockLeaves_snippet.java
Last active December 19, 2015 15:29
Snippet from MineCraft's BlockLeaves.java showing the leaf decay code.
/**
* Ticks the block if it's been scheduled
*/
public void updateTick(World world, int leafX, int leafY, int leafZ, Random random)
{
if (!world.isRemote)
{
int meta = world.getBlockMetadata(leafX, leafY, leafZ);
//If bit 0x8 is set, the leaves will be checked for decay.