Skip to content

Instantly share code, notes, and snippets.

@kopiro
kopiro / bash-tvserie-wiki.bash
Last active October 11, 2015 21:18
Rename in bash title of a TV serie from Wikipedia tables
var commands = [];
var serie = 1;
var serietitle = prompt("Serie Title");
$('table tbody tr').each(function(k)
{
var title = $(this).find('td').eq(2).text();
if (!title) return;
var episode = k<10 ? "0"+k : k;
var finder = "*"+serie+"x"+episode+"*";
commands.push( "mv \"$(find . -name "+finder+")\" \""+serietitle+" - "+serie+"x"+episode+" - "+title+".avi\"" );
@kopiro
kopiro / wrapper-jqueryanimate-css3.js
Created October 22, 2012 12:44
Wrapper for jQuery.animate in CSS (if supported)
$.fn.extend({
cssanimate : function(css_values, anim_time, anim_method, callback)
{
var $this = $(this);
if (!Modernizr.csstransitions)
{
$this.animate(css_values, anim_time, anim_method, callback);
return;
@kopiro
kopiro / multiple-inheritance.php
Created November 12, 2012 23:18
Multiple inheritance on PHP
<?php
class GranFather
{
function a()
{
return 'GranFather.A';
}
function b()
{
@kopiro
kopiro / FBAT.js
Last active October 14, 2015 00:48
try {
(function(){
if (!window.PhotoPermalink) throw "Photo not found on the page.";
var photoInf = PhotoPermalink.getInstance().getCurrentPhotoInfo();
if (!photoInf) throw "Photo not found on the page.";
var jsonList = prompt("Enter your JSON Friends List:\nYou can generate it on: http://kopiro.it/apps/jsonfs", "");
JSONFriends = JSON.parse(jsonList);
@kopiro
kopiro / sort-tag-based.php
Last active December 9, 2015 21:18
Sort in "match" based
<?php
usort($elements, function($a, $b)
{
$pattern = "#tag1|tag2|tag3|tag4#i";
preg_match_all($pattern, $a, $_a);
preg_match_all($pattern, $b, $_b);
return (count($_a[0])<count($_b[0]));
});
@kopiro
kopiro / birilli.gl.cpp
Created December 27, 2012 14:14
Birilli OpenGL
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#include <iostream>
#include <cmath>
using namespace std;
float base_up = 2*sqrt(3);
float base_down = 1;
@kopiro
kopiro / base.gl.cpp
Created December 30, 2012 18:49
OpenGL base C++ project
#include <iostream>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
void renderScene() // this function is called when you need to redraw the scene
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // clear the scene
@kopiro
kopiro / base.adv.gl.cpp
Last active December 10, 2015 10:28
Advanced OpenGL++ base
// g++ src.cpp -­lglut ­-lGL ­-lGLU; ./a.out
#include <iostream>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
// CAMERA position
GLfloat CAMERA_X = 0;
GLfloat CAMERA_Y = 0;
@kopiro
kopiro / export-object-stuct.php
Last active December 10, 2015 22:59
Export all properties, including private/protected/public of an object.
<?php
/* The function */
function ∫($o)
{
$class_regex = "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*";
$code = preg_replace("#{$class_regex}::__set_state#", 'return', var_export($o,1));
return eval($code.';');
}
@kopiro
kopiro / opengl-on-mac.bash
Created January 12, 2013 12:04
How to run C/C++ OpenGL source files on Mac OS X without change the headers
#!/bin/bash
sudo mkdir -p /System/Library/Frameworks/GL.framework/Headers/;
sudo ln -s /System/Library/Frameworks/OpenGL.framework/Headers/gl.h /System/Library/Frameworks/GL.framework/Headers/gl.h;
sudo ln -s /System/Library/Frameworks/OpenGL.framework/Headers/glu.h /System/Library/Frameworks/GL.framework/Headers/glu.h;
sudo ln -s /System/Library/Frameworks/GLUT.framework/Headers/glut.h /System/Library/Frameworks/GL.framework/Headers/glut.h;