Skip to content

Instantly share code, notes, and snippets.

@xexu
xexu / index.html
Last active May 9, 2018
A-Frame custom component
View index.html
<script>
var direction = 1;
AFRAME.registerComponent('auto-camera', {
tick: function () {
var currentPosition = this.el.object3D.position;
if (currentPosition.z < -2) {
direction = 1;
} else if (currentPosition.z > 0) {
direction = -1;
}
@xexu
xexu / index.html
Created May 9, 2018
A-Frame aframe-star-system-component example
View index.html
<script src="https://cdn.rawgit.com/matthewbryancurtis/aframe-star-system-component/db4f1030/index.js"></script>
<a-scene>
<a-sky color="#222"></a-sky>
<a-entity star-system></a-entity>
</a-scene>
@xexu
xexu / index.
Created May 9, 2018
A-Frame assets
View index.
<a-assets>
<a-asset-item id="mtl" src="https://cdn.glitch.com/787f26e4-ded1-4eaf-ba99-e2a5c1ffda59%2Facesjustforroomshow.mtl?1525708212104"></a-asset-item>
<a-asset-item id="obj" src="https://cdn.glitch.com/787f26e4-ded1-4eaf-ba99-e2a5c1ffda59%2Facesjustforroomshow.obj?1525708229479"></a-asset-item>
</a-assets>
<a-entity obj-model="obj: #obj; mtl: #mtl;" position="-1 -1 -1" scale="1 1 1" rotation="0 180 0" shadow></a-entity>
@xexu
xexu / index.html
Created May 9, 2018
A-Frame camera customization
View index.html
<a-entity position="0 1 0">
<a-camera></a-camera>
</a-entity>
@xexu
xexu / index.html
Created May 9, 2018
A-Frame hello world
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello, WebVR! - A-Frame</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" shadow></a-box>
@xexu
xexu / simple-naive-bayes-classifier.php
Created Sep 1, 2015
A PHP classifier in under 50 lines!
View simple-naive-bayes-classifier.php
<?php
function tokenize($string)
{
$string = preg_replace("/ +/", " ", $string);
return explode(" ", strtolower($string));
}
function train($dataset, $text, $class)
{
$tokens=tokenize($text);
@xexu
xexu / HTTPStatusChecker
Created Oct 2, 2014
Check http status of urls in a file
View HTTPStatusChecker
for i in `cat urls.txt`; do curl -s -o /dev/null -w "%{http_code} " $i; echo $i; done
View bdbackup.php
<?php
backup_tables('','','','');
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$database,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($database,$link);
@xexu
xexu / StartsWithEndsWith.php
Last active Aug 29, 2015
Handy StartsWith / EndsWith php functions
View StartsWithEndsWith.php
//http://stackoverflow.com/questions/834303/php-startswith-and-endswith-functions/834355#834355
//Note: Be careful with empty strings, you might want a different behaviour
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
@xexu
xexu / paypal-nvp.php
Created Oct 23, 2013
Script to query paypal nvp api
View paypal-nvp.php
<?php
class Paypal {
/**
* Last error message(s)
* @var array
*/
protected $_errors = array();
/**
* API Credentials