Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@xexu
xexu / index.html
Last active May 9, 2018 10:28
A-Frame custom component
<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 10:25
A-Frame aframe-star-system-component example
<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 10:23
A-Frame assets
<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 10:19
A-Frame camera customization
<a-entity position="0 1 0">
<a-camera></a-camera>
</a-entity>
@xexu
xexu / index.html
Created May 9, 2018 10:10
A-Frame hello world
<!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 September 1, 2015 14:30
A PHP classifier in under 50 lines!
<?php
function tokenize($string)
{
$string = preg_replace("/ +/", " ", $string);
return explode(" ", strtolower($string));
}
function train($dataset, $text, $class)
{
$tokens=tokenize($text);
@xexu
xexu / HTTPStatusChecker
Created October 2, 2014 16:30
Check http status of urls in a file
for i in `cat urls.txt`; do curl -s -o /dev/null -w "%{http_code} " $i; echo $i; done
<?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 August 29, 2015 13:58
Handy StartsWith / EndsWith php functions
//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 October 23, 2013 11:12
Script to query paypal nvp api
<?php
class Paypal {
/**
* Last error message(s)
* @var array
*/
protected $_errors = array();
/**
* API Credentials