Skip to content

Instantly share code, notes, and snippets.

View Maksims's full-sized avatar
🎯
Focusing

mrmaxm Maksims

🎯
Focusing
View GitHub Profile
pc.Angle = function(degrees) {
this._theta = (degrees * pc.Angle.RA) || 0;
this._normalize();
};
// constant to convert between radians and degrees
pc.Angle.RA = 180 / Math.PI;
pc.Angle.prototype = {
copy: function(angle) {
@Maksims
Maksims / map-style.json
Created October 14, 2014 14:30
Google Maps custom dark style
[
{
"elementType": "geometry.fill",
"stylers": [
{ "visibility": "on" },
{ "color": "#324447" }
]
}, {
"elementType": "geometry.stroke",
"stylers": [
@Maksims
Maksims / vec2.js
Last active January 3, 2016 12:49
"rude" extension to Float32Array, implementing 2D Vector Math.
// degree to radians constant
var rd = Math.PI / 180.0;
// 2d vector [x, y] library
var Vec2 = {
cacheSize: 64,
cache: [ ],
clear: function() {
this.cache = [ ];
},
@Maksims
Maksims / class.js
Last active January 19, 2017 18:18
Small implementation of classes with: extend, implement, and check methods
// base class
function Class() { }
// base class name
Class.prototype.className = 'Class';
// lists all parent classes and outputs JSON with it
Class.prototype.toString = function() {
var str = '';
var next = this.__proto__;
@Maksims
Maksims / collection.js
Last active December 20, 2015 21:09
Collections that promise for single appearance of object in collection as well as use hashing based on key (if defined) for collection to speed up checks. In small collections that slows down (nearly unmeasurable) but in 'big' collections (32+) it is a great win to prevent iterations for searches.
'use strict';
var Collection = this.Collection = exports.Collection = function Collection(key) {
this.list = [ ];
this.length = 0;
this.key = key || null;
this.map = { };
}
@Maksims
Maksims / wifi_rssi_windows.js
Created July 25, 2013 22:03
node.js function (for Windows) to get list of SSIDs of wifi networks available, their BSSID and RSSI (Signal Strength). It uses `netsh` windows command line tool to get data. (tested on win7)
var spawn = require('child_process').spawn;
wifiNetworksRSSI(function(err, data, raw) {
if (!err) {
console.log(data); // formatted data with SSID, BSSID, RSSI
// console.log(raw); // raw output from netsh
} else {
console.log(err);
}
});
@Maksims
Maksims / jobsQueue.js
Last active December 16, 2015 16:49
async / sync queue of functions.
function jobsQueue(jobs) {
if (jobs && jobs instanceof Array && jobs.length > 0) {
var count = jobs.length;
var i = -1;
var next = function() {
if (++i < count) jobs[i](next);
}
next();
}
}
@Maksims
Maksims / blueprint.css
Created April 25, 2013 13:04
CSS to generate blueprint grid (blue with white lines), "stolen" from http://tformerjs.com/
background-color : #4e9ad5;
background-size : 100px 100px, 100px 100px, 20px 20px, 20px 20px;
background-position : -11px -1px;
background-image : linear-gradient(rgba(255, 255, 255, .3) 1px, transparent 1px), linear-gradient(0, rgba(255, 255, 255, .3) 1px, transparent 1px), linear-gradient(rgba(255, 255, 255, .1) 1px, transparent 1px), linear-gradient(0, rgba(255, 255, 255, .1) 1px, transparent 1px);
background-image : -webkit-linear-gradient(rgba(255, 255, 255, .3) 1px, transparent 1px), -webkit-linear-gradient(0, rgba(255, 255, 255, .3) 1px, transparent 1px), -webkit-linear-gradient(rgba(255, 255, 255, .1) 1px, transparent 1px), -webkit-linear-gradient(0, rgba(255, 255, 255, .1) 1px, transparent 1px);
background-image : -moz-linear-gradient(rgba(255, 255, 255, .3) 1px, transparent 1px), -moz-linear-gradient(0, rgba(255, 255, 255, .3) 1px, transparent 1px), -moz-linear-gradient(rgba(255, 255, 255, .1) 1px, transparent 1px), -moz-linear-gradient(0, rgba(255, 255, 255, .1) 1px, transparent 1px
@Maksims
Maksims / DOMClass.js
Last active February 1, 2020 17:14
HTMLElement extension to add, remove, toggle, detect Classes.
HTMLElement = typeof(HTMLElement) != 'undefiend' ? HTMLElement : Element;
HTMLElement.prototype.addClass = function(string) {
if (!(string instanceof Array)) {
string = string.split(' ');
}
for(var i = 0, len = string.length; i < len; ++i) {
if (string[i] && !new RegExp('(\\s+|^)' + string[i] + '(\\s+|$)').test(this.className)) {
this.className = this.className.trim() + ' ' + string[i];
}