Skip to content

Instantly share code, notes, and snippets.

@grownseed
grownseed / prime.js
Created July 8, 2012 03:22
JavaScript Euler's sieve implementation for generating an array of prime numbers
/*
To return an array of all prime numbers below 1000:
primeRange(1000);
*/
function primeRange(max)
{
var max_sqrt = Math.sqrt(max),
range = [],
current = 0;
@grownseed
grownseed / HaibuInstall.md
Last active December 10, 2015 23:08
Installing Haibu for Node.js deployment

Haibu Install (CentOS)

Install Node/NPM

su - 
yum install openssl-devel gcc-c++
cd /usr/local/src
//in main app.js
var auth = require('./lib/auth');
//...
app.use(auth.checkPermissions());
//in lib/auth.js
exports.checkPermissions = function() {
return function checkPermissions(err, req, res, next) {
//sometimes this simply never kicks in,
//adapted from https://github.com/mgcrea/angular-strap/blob/master/src/directives/datepicker.js
app.directive('datetime', ['$timeout', function($timeout) {
'use strict';
var DATE_REGEXP_MAP = {
'/' : '[\\/]',
'-' : '[-]',
'.' : '[.]',
dd: '(0?[1-9]|[1-2][0-9]|3[0-1])\\b',
MM: '(0?[1-9]|1[0-2])\\b',
app.directive('datetime', ['$timeout', function($timeout) {
'use strict';
var DATE_REGEXP_MAP = {
'/' : '[\\/]',
'-' : '[-]',
'.' : '[.]',
dd: '(0?[1-9]|[1-2][0-9]|3[0-1])\\b',
MM: '(0?[1-9]|1[0-2])\\b',
yyyy: '(\\d{4})\\b',
> iconv@2.0.4 install /root/tmp/tmp-25208tcl53wg/build/package/node_modules/mail
parser/node_modules/iconv
> node-gyp rebuild
make: Entering directory `/root/tmp/tmp-25208tcl53wg/build/package/node_modules/
mailparser/node_modules/iconv/build'
CC(target) Release/obj.target/iconv/deps/libiconv/libcharset/lib/localcharset.
o
CC(target) Release/obj.target/iconv/deps/libiconv/lib/iconv.o
CXX(target) Release/obj.target/iconv/src/binding.o
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: npm http GET https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/jade
npm http GET https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/passport
npm http GET https://registry.npmjs.org/passport-google-oauth
npm http GET https://registry.npmjs.org/connect-flash/0.1.0
npm http GET https://registry.npmjs.org/connect-mongo
npm http GET https://registry.npmjs.org/xoauth2
angular.module('magnet.services', []).
config(['$httpProvider', function($httpProvider) {
var interceptor = ['$q', '$rootScope', function($q, $rootScope) {
//handle notifications at root
if (!$rootScope.notifications) {
$rootScope.notifications = [];
$rootScope.removeNotification = function(n) {
$rootScope.notifications = $rootScope.notifications.filter(function(notification) {
return notification != n;
});
{} + [] >>> 0
parseInt({} + []) >>> NaN
!{} > ~{} >>> true
~[] >>> -1
{} + 0 + [] >>> "0"
0 + {} + [] >>> "0[object Object]"
{} + [] + 0 >>> 0
typeof null === 'object' && null !== undefined && null == undefined >>> true

Mental Games

It'll come as no surprise to anybody here that the human brain is pretty amazing, and I often wonder how far it can be pushed, or how much control you have over it (or your body by extension). I won't get into any metaphysical considerations here or anything like that, I'd just like to share something I do quite often and hope other people share too.

As far back as I can remember, I've been making up and playing mental games with myself. I didn't really do it consciously until I was maybe about 7 or 8, but as of today I still do pretty much all of them. They generally take no more than a few minutes and I think they're quite an interesting way of exercising your mind and figuring things about how you work.

I'm not sure whether this will come through as absolute lunacy or total stupidity on my part, but this isn't something I've ever seen discussed and I'm genuinely interested in it.

Here are some of my favorites: