Skip to content

Instantly share code, notes, and snippets.

View ghostwriter's full-sized avatar
🐘
while(!succeed=try())

Nathanael Esayeas ghostwriter

🐘
while(!succeed=try())
  • 0.0.0.0
View GitHub Profile
@ghostwriter
ghostwriter / relative-size.js
Created February 4, 2016 20:07
Increase or decrease CSS values with jQuery
/*
cleaner than hard-coding the desired font size
refs: http://api.jquery.com/css/
some use case:
all these websites that use *huge* font sizes,
painful to read even on a 1920x1080 screen.
*/
$('.article-content').css('font-size', '-=2');
@ghostwriter
ghostwriter / dom_insertion.js
Created February 4, 2016 20:05
Quick 'n Dirty DOM insertion Function when there is no JS library
// More elaborate code can be found here:
// https://github.com/jquery/jquery/blob/master/src/manipulation.js
function prepend(target, elem) {
target.insertBefore(elem, target.firstChild);
}
function append(target, elem) {
target.appendChild(elem);
}
@ghostwriter
ghostwriter / User.php
Created February 4, 2016 19:41
Laravel Eloquent Query Scopes - OrderByRandom
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* Scope a query to return a random users Model.
@ghostwriter
ghostwriter / OrderByRandomTrait.php
Created February 4, 2016 19:14
Laravel Eloquent OrderByRandom
<?php
trait OrderByRandomTrait
{
/**
* Scope to order by random.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOrderByRandom($query)
@ghostwriter
ghostwriter / js_addevent.md
Created January 21, 2016 07:56
Allows you to assign an event handler to an element.

addEvent ()

Allows you to assign an event handler to an element.

Code:

function addEvent(obj, eventName, callback){
	if (obj.addEventListener){
		obj.addEventListener(eventName, callback, false);
	} else if (obj.attachEvent){
@ghostwriter
ghostwriter / gist:bcaba56977f20b14dc5b
Last active July 1, 2022 07:28
BattleTale Bug #29 (reproducible bug)
/*
1. post a link in chat. (ex. https://github.com/)
2. post anything with 3 or more "w"s in a row. (ex. www, wowww,wwwwwwwwww)
3. use {/geturl} and you'll get the word with the 3 "w" in it and not the url.
Fix: Validate url.
*/
var url:String = "http://www.google.com";
var regex:RegExp = /^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i;
trace(regex.test(url)); // returns true if valid url is found
@ghostwriter
ghostwriter / 408721.js
Created December 10, 2014 12:44
On Firefox, offsetWidth and offsetHeight are undefined on a SVG element.
getSize : function () {
if (isBody(this))
return this.getWindow().getSize();
return {
x : this.offsetWidth || styleNumber(this, 'width'),
y : this.offsetHeight || styleNumber(this, 'height')
};
}