Skip to content

Instantly share code, notes, and snippets.

View dimorphic's full-sized avatar
🤖
*void 0*

Sabin Tudor dimorphic

🤖
*void 0*
View GitHub Profile
@katowulf
katowulf / no_dup_emails.js
Last active May 17, 2020 10:43
Enforce no duplicate emails in Firebase
/**
* My Firebase data structure:
*
* /email_index/$email/user_id
* /user/$user_id/email
*/
var fb = new Firebase(URL);
function isDuplicateEmail(email, callback) {
@katowulf
katowulf / push_to_urbarairship.js
Last active February 16, 2016 13:58
Node.js process to queue from Firebase to Urban Airship.
// UNTESTED; THEORETICAL, based on http://docs.urbanairship.com/connect/ios_push.html
https://github.com/mikeal/request
var request = require('request');
/** Presumably the snapshot will contain something like this:
*
{
"audience": {"device_token": "FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660"},
"notification": {
@katowulf
katowulf / module.simpleLoginTools.js
Last active March 3, 2016 04:26
A service and several directives based on ng-cloak, which wait for angularFire to finish authenticating--rather than just until Angular bootstraps--before displaying it's content. Handy to get rid of those blips that display when user isn't logged in--oh, wait, now they are.
'use strict';
/**
* This module monitors angularFire's authentication and performs actions based on authentication state.
* directives/directive.ngcloakauth.js depends on this file
*
* Modify ng-cloak to hide content until FirebaseSimpleLogin resolves. Also
* provides ng-show-auth methods for displaying content only when certain login
* states are active.
*
@zhangwc
zhangwc / ThreeJS draw image.js
Created November 27, 2013 05:45
use THREE.SpriteMaterial and canvas to create text and image in 3D scene
{
var texture = new THREE.ImageUtils.loadTexture( 'images/img.jpg' );
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({
map: texture,
useScreenCoordinates: false,
alignment: THREE.SpriteAlignment.center,
transparent: true
});
@i8ramin
i8ramin / Gruntfile.js
Created December 15, 2013 15:06
Modified Gruntfile.js and package.json files to work with Appgyver Steroids
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,**/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// show elapsed time at the end
@branneman
branneman / better-nodejs-require-paths.md
Last active May 15, 2025 11:17
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@serverwentdown
serverwentdown / server.js
Last active January 29, 2019 20:18 — forked from mixonic/server.js
// Bug fixes for current versions.
//
// This server will start a bash shell and expose it
// over socket.io to a browser. See ./term.html for the
// client side.
//
// You should probably:
//
// npm install socket.io
@hasdavidc
hasdavidc / storagePolyfill.js
Last active June 9, 2020 20:55
A LocalStorage polyfill that also works in private browsing Safari (by doing window.localStorage.__proto__ = ourPolyfillObject) (where window.localStorage !== 'undefined', but has a quota of 0 and throws an error when you try to setItem)
//variant of https://gist.github.com/Contra/6368485
(function () {
var isStorageAvailable = function (storage) {
if (typeof storage == 'undefined') return false;
try { // hack for safari incognito
storage.setItem("storage", "");
storage.getItem("storage");
storage.removeItem("storage");
@szalishchuk
szalishchuk / ip.js
Last active December 14, 2022 11:04
Get local external ip address with nodejs
var
// Local ip address that we're trying to calculate
address
// Provides a few basic operating-system related utility functions (built-in)
,os = require('os')
// Network interfaces
,ifaces = os.networkInterfaces();
// Iterate over interfaces ...
@edankwan
edankwan / snoise2d.js
Created April 6, 2014 06:42
2d snoise Javascript post
// port from GLSL code base on https://github.com/ashima/webgl-noise/blob/master/src/noise2D.glsl
//JS SNOISE PORT
function snoise2d(x, y) {
var C0 = 0.211324865405187;
var C1 = -0.577350269189626;
var C2 = 1.79284291400159;
var OVER_289 = 1 / 289;