Skip to content

Instantly share code, notes, and snippets.

View nijikokun's full-sized avatar
🍀
working

Niji nijikokun

🍀
working
  • Product Manager
  • San Diego, California
View GitHub Profile
@nijikokun
nijikokun / Color.js
Created August 22, 2011 02:50
Simple RGBA Color manager for JS, Needed for C# style
var Color = {
initialize: function(R, G, B, A){
function verify(i) {
return (!is_int(i) || i < 0 || i > 255) ? 255 : i;
}
this.R = verify(R);
this.G = verify(G);
this.B = verify(B);
this.A = verify(A);
@nijikokun
nijikokun / changelog.md
Created September 2, 2011 02:14
MinPubSub for PHP - Finally, Works fully now.

MPS 0.0.7 (2011-1-9)

  • minpubsub.php

  • Fixed issues with unsubscribe

  • PHP doesn't support || for variables, used inline if statement.

  • Don't trust $sub to change self::$cache * Changed $callback to $call on local variable * Since we would do the check for callback to handle or handle[1], put as variable and check once.

  • index.php

@nijikokun
nijikokun / three.demo.js
Created September 12, 2011 23:48
Three.js Demo / Tutorial / Example. Revised code style / comments.
/**
* Revised three.js example.
*
* @author Nijikokun (@nijikokun)
* @original-author Paul Lewis (@aerotwist)
*
* @changelog
* 0.3 Fixed Commenting to be more descriptive.
* 0.2 Fixed JavaScript Coding style
* 0.1 Initial Creation
@nijikokun
nijikokun / sprintf.js
Created October 28, 2011 17:27
String formatting for special things, sprintf, date
// Copyright AOL <http://aol.nexua.org> 2011
// Author: Nijikokun
if (!String.prototype['%']) {
String.prototype['%'] = function() {
function get_type(variable) {
return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
}
function str_repeat(pattern, count) {
if (count < 1) return '';
@nijikokun
nijikokun / t.js
Created November 3, 2011 01:27
<= (chars 140) Javascript
// t (in CoffeeScript)
//
// Description: Quick Templating, optional customizing open/closing tags
//
// Author: Nijikokun <[email protected]>
//
// Usage:
//
// t('Hello {name}!', { name: 'World' });
//
@nijikokun
nijikokun / README.md
Created November 3, 2011 01:42
Less Than 140 Chars - JS

<= (chars 140)

A collection of js functions that are less than or equal to 140 characters.

  • t - Quick templating function with optional custom brackets (js | coffee)
@nijikokun
nijikokun / math.rgb.js
Created November 15, 2011 22:04
Actual Hex to RGB/ARGB
// Math.RGB()
// Actual Hex to RGB values, Invalid hex returns 0,0,0 or black.
//
// By Nijikokun
//
// Usage:
// 8 bit
// Math.RGB(0xFF)
//
// 12 bit
@nijikokun
nijikokun / enumerable.js
Created February 17, 2012 04:19
Probably the hackiest enumerator i've built, Javascript.
// Without the use of yield or enumerable definitions javascript makes enumerating over objects
// very difficult and verbose.
// Goes in Rectangle.js of my Geometry.js class
this.trace = function(f) {
if(this.width() > 1 && this.height() > 1) {
// top
(Rectangle.row(
this.topLeft(), this.width() - 1
)).enumerate(f);
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@nijikokun
nijikokun / zocial.css
Created May 16, 2012 00:30
Better Zocial Button CSS, Anti-Aliasing, Smoother Shadows and Better Borders and Colors
@charset "UTF-8";
/*!
Code written by Sam Collins (@smcllns) of www.eventasaur.us
You are free to use this work commercially
You are free to extend this work without permissions from the author (just do so tastefully eh?)
Enjoy
*/
/* Reference icons from font-files */