Skip to content

Instantly share code, notes, and snippets.

View forestrf's full-sized avatar

Andrés Leone Gámez forestrf

View GitHub Profile
<?php
function parseFavicon($html) {
$s = '[ \t\r\n]*?';
// Get the 'href' attribute value in a <link rel="icon" ... />
// Also works for IE style: <link rel="shortcut icon" href="http://www.example.com/myicon.ico" />
// And for iOS style: <link rel="apple-touch-icon" href="somepath/image.ico">
$matches = array();
// Search for <link rel="icon" type="image/png" href="http://example.com/icon.png" />
;
@forestrf
forestrf / scrollTo
Last active August 29, 2015 14:10
scroll page to an element in the document or a top-pixel position
// http://stackoverflow.com/questions/8917921/cross-browser-javascript-not-jquery-scroll-to-top-animation/23844067#23844067
// e = element to scroll to or top position in pixels, d = time to scroll in ms
function scrollTo(e,d){if(d>=0){var h=document.documentElement;if(h.scrollTop===0){var t=h.scrollTop;++h.scrollTop;h=t+1===h.scrollTop--?h:document.body}typeof e==="object"&&(e=e.offsetTop);scrollToX(h,h.scrollTop,e,0,1/d,20)}}
/*
e = scrollable element
a = initiall scrollable element position (from)
b = height to scroll to (to)
t = lerp from a to b (0 - 1)
v = speed. input 1 / time to scroll
/* **************************************************************************
Copyright 2012 Calvin Rien
(http://the.darktable.com)
Derived from a method in BuildManager, part of
VoxelBoy's Unite 2012 Advanced Editor Scripting Talk.
(http://bit.ly/EditorScripting)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@forestrf
forestrf / add(3)(5)....valueOf().js
Last active August 29, 2015 14:13
add(1)()(3)(8).valueOf();
function add() {
var slice = Array.prototype.slice, t = 0;
function add2(k) {
k = slice.call(arguments);
for(var j in k)
t += k[j];
return add2;
}
add2.valueOf = function(){return t};
return add2.apply(null, slice.call(arguments));
@forestrf
forestrf / youtube playlist2html bookmarklet.js
Last active August 29, 2015 14:17
Youtube Playlist 2 HTML
var tabla_videos = document.getElementById("pl-video-table");
var boton_siguiente = tabla_videos.nextSibling.nextSibling;
console.log(tabla_videos);
console.log(boton_siguiente);
carga_mas_videos(function() {
//Todos los vídeos están cargados
@forestrf
forestrf / CameraRadiusUnity.cs
Last active December 18, 2016 19:13
Get the minimum radius of a sphere around an Unity3D Camera that guarantees that outside of that radius nothing will intersect the camera's frustum
// Get the minimum radius sphere of a camera in which the camera crosses something. For a spherecast, for example.
public static float GetRadiusOfCamera(Camera camera) {
/*
Calculate the radius of the smallest sphere that contains perfectly the camera
The vertices of the sides of the near plane must touch the sphere and the
and also from the near plane center going backwards by camera.nearClipPlane
SIDE
_________
/ /| \
@forestrf
forestrf / SobelFilter.shader
Created January 27, 2017 21:53 — forked from mattatz/SobelFilter.shader
Sobel filter shader for Unity.
Shader "Mattatz/SobelFilter" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_DeltaX ("Delta X", Float) = 0.01
_DeltaY ("Delta Y", Float) = 0.01
}
SubShader {
Tags { "RenderType"="Opaque" }
@forestrf
forestrf / UnityScriptReloadFixer.cs
Last active July 26, 2018 19:10
[FIXED BY UNITY. This is not needed at all anymore] Unity sometimes does not reload my scripts when reimporting them. Apparently the .dlls inside /Library/ScriptAssemblies are not always replaced by the generated dlls inside /Temp, so this scripts moves those dlls automatically
using System;
using System.IO;
class Program {
static void Main(string[] args) {
Console.WriteLine("Close this window when you are finished doing cool progress");
Console.WriteLine("first argument: path to Library folder");
// Path
string path = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Directory.FullName;
@forestrf
forestrf / ajax.js
Last active August 30, 2017 11:04
Easy ajax function that supports post data in text form, or a reference to a DOM form object
// callback takes one argument
// http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery
// data = null or undefined para usar GET
AJAX = function(url, data, callbackOK, callbackFAIL, timeout) {
if (callbackFAIL === undefined) callbackFAIL = function(x){};
if (callbackOK === undefined) callbackOK = function(x){};
if (isNaN(timeout)) timeout = 30000;
var isPost = data !== undefined && data !== null;
var x = new XMLHttpRequest();
if (isPost) x.open('POST', url, true);
@forestrf
forestrf / FastByteConverter.cs
Last active June 30, 2022 07:41
c# structs to convert easily and fast between simple types and an array of bytes
using System;
using System.Runtime.InteropServices;
namespace Ashkatchap.BitUtils {
public enum Endianness {
/// <summary>
/// Network Byte order
/// </summary>
Big = 0,
/// <summary>