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 / DB test
Created October 10, 2012 02:22
tells you how much it would take to add several lines in your db
<?
ini_set('max_execution_time',0);
//tells you how much it would take to add several lines in your db, change ur password and all that off //course..
//_GET[i] is the ammount of lines
$time_start = microtime(true);
$sql = mysql_connect('localhost','root','magic');
mysql_select_db('test',$sql);
mysql_set_charset('utf8');
@dvidsilva
dvidsilva / q2ar.fn.php
Created September 30, 2012 07:23
Returns the result of a query as an array
//receives a query and returns an array in the following format
// array['row-number']['field_name'] = 'value'
function q2ar($query){
$query = $this->mysql($query);
$n=0;
$data = '';
if(is_resource($query)){
while($row = mysql_fetch_row($query) ){
$i=0;
while ($i < mysql_num_fields($query)){
@dvidsilva
dvidsilva / table.fn.php
Created September 30, 2012 07:21
Auto Create a Table from an associative 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]);
//
// loveWins(): a simple function that accepts a UIImage and
// returns the same image blended with the rainbow flag
// of the LGBT pride movement.
//
// This is released for pedagogical reasons (I've tried to make
// the code as easy to follow as possible!) but you're welcome
// to use it for any purpose – consider the code yours.
//
// If you're using Xcode 7 / Swift 2, you need to make a tiny
@dvidsilva
dvidsilva / appendscript.js
Last active August 29, 2015 14:17
Add a js file based ona variable
document.addEventListener("DOMContentLoaded", function() {
var src, scriptTag;
src = "./app.js"; // here goes the name of the file to include
scriptTag = document.createElement('SCRIPT');
scriptTag.src = src;
document.body.appendChild(scriptTag);
});
@dvidsilva
dvidsilva / README.md
Last active August 29, 2015 14:17 — forked from nikcub/README.md
window.addEventListener("orientationchange", handleOrientation, true);
function handleOrientation(){
if (Math.abs(window.orientation) == 90) {
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-landscape.png");
angular.element(document.querySelector('#imagen-Background')).css("width","35%");
} else {
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-portrait.png");
angular.element(document.querySelector('#imagen-Background')).css("width","45%");
}
@dvidsilva
dvidsilva / es6
Created February 3, 2015 02:34
es6 and recursion, examples from http://raganwald.com/2015/02/02/destructuring.html
const length = ([first, ...rest]) =>
first === undefined
? 0
: 1 + length(rest);
const flatten = ([first, ...rest]) => {
if (first === undefined) {
return [];
}
@dvidsilva
dvidsilva / imgur.rb
Created December 9, 2014 11:59
Imgur API wrapper for Ruby
# require 'imgur/version'
require 'httparty'
require 'net/http'
module Imgur
HTML_PATH = 'https://imgur.com/'
API_PATH = 'https://api.imgur.com/3/'
UPLOAD_PATH = 'upload'
IMAGE_PATH = 'image/'
@dvidsilva
dvidsilva / designer.html
Created November 16, 2014 17:58
designer
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;