Skip to content

Instantly share code, notes, and snippets.

@rasec
rasec / squares.js
Last active November 8, 2020 21:09
for(let i = 0; i < 2000; i++) {
const square = document.createElement('div');
square.style.backgroundColor = 'rgb(' + (Math.random() * 255) + ', ' + (Math.random() * 255) + ', ' + (Math.random() * 255) + ')';
square.style.position = 'absolute';
square.style.left = (Math.random() * 950) + 'px';
square.style.top = (Math.random() * 950) + 'px';
square.style.width = '50px';
square.style.height = '50px';
document.body.appendChild(square)
}
@rasec
rasec / index.html
Created June 2, 2020 14:48
Tic Tac Toe
<div id="errors" style="
background: #c00;
color: #fff;
display: none;
margin: -20px -20px 20px;
padding: 20px;
white-space: pre-wrap;
"></div>
<div id="root"></div>
<script>
@rasec
rasec / handleBgImageLoad.js
Created June 29, 2012 10:22
Handler background image load
var handlerBgImage = function(){
var auxImg = new Image();
auxImg.id = "auxImg"; // the bg image id;
auxImg.src = ""; // the bg image;
handleLoad(auxImg);
document.body.appendChild(auxImg);
}
var handleLoad = function(auxImg){
if(auxImg.addEventListener) {
@rasec
rasec / extractVideo.sh
Created June 29, 2012 10:16
Extract the video image (not audio) of a video
ffmpeg -i <input_video> -an -vcodec copy <output_video>
@rasec
rasec / returnInt.js
Created April 16, 2012 13:51
Parse Int for map method
// Seen at MDN map function description
var returnInt = function(element){
return parseInt(element,10);
};
@rasec
rasec / removeIndex.js
Created April 16, 2012 13:50
Simple Array Remove
// Simple Array Remove - By César de la Cruz (MIT Licensed)
Array.prototype.removeIndex = function(index){
var rest = this.slice(index+1);
this.length = index;
return this.push.apply(this, rest);
};
@rasec
rasec / getDataFromUrl.php
Created April 12, 2012 11:13
PHP Get Data using CURL
<?php
function getDataFromUrl($url) {
$ch = curl_init();
// Set URL and header options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
// Start to capture the output
ob_start();
@rasec
rasec / getradiovalue.js
Created March 27, 2012 14:03
radio buttons value
var getRadioValue = function(radioName){
var radios = document.getElementsByName(radioName);
for( i = 0; i < radios.length; i++ ) {
if( radios[i].checked ) {
return radios[i].value;
}
}
return null;
}
@rasec
rasec / gist:994955
Created May 27, 2011 09:45
Get the Host of a URL
<?php
function getHost ($url) {
return preg_replace("/^(http[s]?:\/\/|ftp:\/\/)?((www\.)?[a-zA-Z0-9][a-zA-Z0-9-\.]*\.(com|org|net|mil|edu|ca|co.uk|com.au|gov|es))\/(.*)$/", "$2", $url);
}
?>