Skip to content

Instantly share code, notes, and snippets.

View Bloodb0ne's full-sized avatar

Emilian Bloodb0ne

View GitHub Profile
@Bloodb0ne
Bloodb0ne / gist:2b47a8037631aeee905f
Created October 26, 2014 08:35
CakePHP permissions view
SELECT
perm.id,
aco_child.alias as controller,
aco_parent.alias as action,
_create,_read,_update,_delete,
requester.model as requester_type
FROM
acos as aco_child
JOIN acos as aco_parent ON aco_child.id = aco_parent.parent_id
JOIN aros_acos as perm ON perm.id = aco_parent.id
<?php
//Helpers
function s($text){
return "\"".trim($text," }{")."\"";
}
function m1($m){
return s($m[1]) . ":" . s($m[2]);
}
function m2($m){
@Bloodb0ne
Bloodb0ne / image_placeholders.js
Last active August 29, 2016 12:36
Simple implementation of image placeholders using canvas and dataUrl. Contains a version in vanilla and one using jquery
//JQUERY version
$(document).ready(function(){
function imgPlaceholders(tc,bgc,datr){
function createPlaceholder(w,h,s){
var canvas = $('<canvas>');
var canvasr = canvas[0];
canvas.attr('width',w).attr('height',h);
var ctx = canvasr.getContext('2d');
ctx.fillStyle = bgc;
ctx.fillRect(0,0,w,h);
@Bloodb0ne
Bloodb0ne / menu-to-json.js
Created August 12, 2015 17:48
Random Html Menu -> Json
function reparseElements($container){
return $container.map(function($ind,$item){
if($($item).children('ul').length != 0){
return {
title:$($item).children('a').text(),
children: reparseElements($($item).children('ul').children('li')).get()
};
}
return { title:$($item).children('a').text() };
});
<?php
$x = range(40,45,0.25);
$y = range(20,29,0.25);
// var_dump($x);
$v = 43.1;
$v2 = 21.4;
function get4GridPoints($xrange,$yrange,$x,$y,$eps = 0.25){
<?php
function jpegStrip($path){
$image = imagecreatefromjpeg($path);
list ($w, $h) = getimagesize($path);
$height = ( 40*$h / $w );
$thumb = imagecreatetruecolor(40, $height);
imagecopyresized($thumb,$image,0,0,0,0,40,$height,$w,$h);
@Bloodb0ne
Bloodb0ne / nsfw_9gag.txt
Created January 25, 2016 12:35
Url templates for 9gag
http://img-9gag-fun.9cache.com/photo/<ID>_460sv.webm
http://img-9gag-fun.9cache.com/photo/<ID>_700b.jpeg
@Bloodb0ne
Bloodb0ne / share.js
Created June 20, 2016 10:44
Share buttons
function fbShare(url, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
// window.open('http://www.facebook.com/sharer.php?u=100&p[title]=' + name + '&p[summary]=' + desc + '&p[url]=' + url + '&p[images][0]=' + img, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
window.open('http://www.facebook.com/share.php?u='+url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
function twitterShare(url, desc, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('https://twitter.com/intent/tweet?url='+ url + '&text=' + desc , 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
@Bloodb0ne
Bloodb0ne / lookAtAssets.py
Last active August 22, 2016 06:25
Fetching all js files and formatting them from an url.
import urllib3
import sys,os
import argparse,jsbeautifier
from bs4 import BeautifulSoup
from bs4 import UnicodeDammit
def writeScript(path,data):
#Nice side effect bruh
print('Writing to :=',path)
f = open(path,'w',encoding="utf-8")
@Bloodb0ne
Bloodb0ne / image_centering.js
Created April 23, 2017 07:31
A scaling function to fit images into a predefined canvas with callback
function drawImageScaled(src,w,h,callback) {
var img = $('<img>').attr('src',src);
img.on('load',function(){
var image = img[0];
var canvas = $('<canvas>').attr('width',w).attr('height',h)[0];
var ctx = canvas.getContext("2d");
// var canvas = ctx.canvas ;
var hR = canvas.width / image.width ;
var vR = canvas.height / image.height ;