Skip to content

Instantly share code, notes, and snippets.

View dvidsilva's full-sized avatar
❤️
Enamorao

Daveed Silva dvidsilva

❤️
Enamorao
View GitHub Profile
@dvidsilva
dvidsilva / semana.com
Created May 31, 2013 08:37
js/css/http errors in semana.com/something
Uncaught ReferenceError: FB is not defined loginUser.js:295
GET http://us.img.e-planning.net/layers/epl-41.js eplanningv4.js:33
GET http://ads.us.e-planning.net/egc/4/115d eplanningv4.js:37
duplicate in.js loaded, any parameters will be ignored in.js:5
FB.init has already been called - this could indicate a problem all.js:52
GET http://ads.us.e-planning.net/eb/3/11f3/73cc9abac23ff22f?o=j&rnd=677740114001&crs=UTF-8 344547-3:476
Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:235
Unknown RPC service: widget-interactive-I0_1369989299823 cb=gapi.loaded_0:121
Unknown RPC service: widget-interactive-I1_1369989300057 cb=gapi.loaded_0:121
GET http://adserver.cxad.cxense.com/adserver/search?media=javascript&asId=00000…791904247277&prnd=9txmm0pjksw4&tzo=300&rnd=1099849022&callback=cX.cX8k0g7t cx.js:537
@dvidsilva
dvidsilva / Hours2mins
Created June 24, 2013 17:16
Function to convert 90 minutes into 01:30:00
public function Hours2Mins($time, $format = '%s:%s:%s')
{
settype($time, 'integer');
if ($time < 0 || $time >= 1440) {
return;
}
$hours = sprintf('%02d', floor($time/60) );
$minutes = sprintf('%02d', $time%60);
$seconds = '00';
return sprintf($format, $hours, $minutes , $seconds );
@dvidsilva
dvidsilva / filescan.php
Created June 26, 2013 06:58
listar archivos en directorio
<?php
$handler = opendir($directory);
foreach($files as $f){
if(!in_array($f,array('.','..') ) )
echo $f, '<br/>';
}
closedir($handler);
/*cambia foldername por ../ vuelvelo a subir y mira la magia y luego por ../../ y asi :P o por ../nombredeotrodir
/* hasta encontrar lo que buscas
var total = 0;
var suma = 0;
$.each($("input"), function (index, value) {
total = total + 1 ;
if( $(value).val() != '' ){
suma = suma + 1 ;
}
});
@dvidsilva
dvidsilva / table
Created July 13, 2013 18:42
creates a table using an array
public function table($array,$headers,$title){
$table = '';
$table .= "<table id=table class=table >\n";
if($title != ''){
$table .= "<caption >$title</caption>\n";
}
$table .=" <thead><tr>\n";
$r = 1;
if(!is_array($headers)){
$headers = array_keys($array[0]);
<?php
public function rules()
{
return array(
array('roleid', 'verificarCodigo'),
);
}
@dvidsilva
dvidsilva / jquery insert
Created September 4, 2013 04:37
Programmatically add jquery to a page
var head = document.getElementsByTagName("head");
var node = document.createElement("script");
node.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js";
head[0].appendChild(node);
@dvidsilva
dvidsilva / the best js file there is in the universe
Created September 26, 2013 07:40
Get all background images in a page and create a canvas/sprite with them, with plain js
document.getElementsByTagName("body")[0].innerHTML += '<canvas id=sprite ></canvas>';
var items = document.getElementsByTagName("*");
var c = document.getElementById("sprite");
c.width = 4000;
c.height = 10000;
c.style.border = '1px solid black';
var y = 0;
var x = 0;
@dvidsilva
dvidsilva / Patterns in string
Last active December 25, 2015 13:59
Find the places where certain pattern occur in a string using JS, keeping in mind interpolation and not repeating the result. Is using node :P
var start = new Date().getTime();
var str="";
var mtc="CTTGATCAT";
var n = " ";
var alr = new Array();
var j = 0;
var url = 'https://beta.stepic.org/media/attachments/lessons/3/Vibrio_cholerae.txt';
var http = require('https');
var fs = require('fs');
@dvidsilva
dvidsilva / Google analytics in coffescript
Created October 15, 2013 22:30
I'm using chaplin and brunch, in coffeescript, bit of a mess, this is how we implemented the google analytics tracking code the following was put in the app/base/controller.coffe in beforeAction: (params, route) ->
((i, s, o, g, r, a, m) ->
i["GoogleAnalyticsObject"] = r
i[r] = i[r] or ->
(i[r].q = i[r].q or []).push arguments
i[r].l = 1 * new Date()
a = s.createElement(o)
m = s.getElementsByTagName(o)[0]