Skip to content

Instantly share code, notes, and snippets.

View agalazis's full-sized avatar
🌴
On vacation

Andreas Galazis agalazis

🌴
On vacation
View GitHub Profile

They say that one of the pros of NodeJS is that you use the same language on the back-end and the front-end, so it's easy to share code between them. This sounds great in theory, but in practice the synchronous dependency handling in NodeJS works completely different than any client-side frameworks (which are asynchronous).

Usually that means that you end up copy-pasting your code between your NodeJS sources and your client-side sources, or you use some tool like Browserify, which is brilliant, but they add an extra step in the build process and most likely will conflict with the dependency handling of the framework of your choice (like AnularJS DI). I couldn't look in the mirror if I would call that code sharing.

Fortunately, with a couple of lines of boilerplate code, you can write a module which works in NodeJS and AngularJS as well without any modification.

No globals in the front-end, and dependencies will work. The isNode and isAngular va

$ cat test.js
function foo () { while (true) { } }
function bar () { return foo(); }
bar();
$ node test.js &
$ gdb attach $(pidof node)
0x00000bf778c63d5f in ?? ()
(gdb) b v8::internal::Runtime_StackGuard
Breakpoint 1 at 0x84a1f0
(gdb) print 'v8::V8::TerminateExecution'(0)
@agalazis
agalazis / svgDirToJSONPaths
Last active December 5, 2015 08:27
convering an svg directory to a json file containing paths
#!/bin/bash
DIR=$( pwd )&&DIR=${DIR//[[:space:]]/}&&DIR=${DIR##*/}; echo var $DIR \= \{ >$DIR.json; ls *.svg | while read fname ; do echo ${fname%.*}:"$(extract-svg-path $fname --quote)", >> $DIR.json; done;echo \} >>$DIR.json
@agalazis
agalazis / linboxSetup
Last active December 20, 2015 22:03
Linbox Setup Script
#!/bin/bash
cd ~&&curl http://download2.mikrotik.com/routeros/winbox/3.0/winbox.exe>winbox.exe\
&& echo "alias linbox='/usr/bin/wine ~/winbox.exe'" >> ~/.bashrc\
&& exec bash
@agalazis
agalazis / average-age.js
Created December 27, 2015 21:46 — forked from bennadel/average-age.js
The Best Way To Compute The Average Age Of Cat Owners In Functional Programming
var _ = require( "lodash" );
// Assume a collection that has:
// - age: Number
// - hasCat: Boolean
var people = require( "./people.json" );
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
python -m SimpleHTTPServer
@agalazis
agalazis / README.md
Created February 24, 2016 19:45 — forked from kjantzer/README.md
Backbone.js & Underscore.js Natural Sorting

Backbone.js & Underscore.js Natural Sorting Algorithm

Backbone is great but I continually found the default sorting method limited due to the following:

Disc 1, Disc 2, … Disc 10 would become Disc 1, Disc 10, Disc 2

With the help of Jim Palmer's naturalSort.js, I was able to integrate natrual sorting into Backbone.Collection.

Backbone collections are automatically sorted and now, by simply adding sortType:"natural", your collections can be sorted naturally.

@agalazis
agalazis / GULP.noob.markdown
Last active June 11, 2016 18:10
Cheat sheets for the noob..... Cheat sheets written when I was a noob at using some tech...

#GULP

#DI:
##Intro
(nice mock example at 19:30)
https://www.youtube.com/watch?v=_OGGsf1ZXMs
###Injectors providers dpendencies explained:
http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html
#Agular shadow dom
https://www.youtube.com/watch?list=PLOETEcp3DkCq788xapkP_OU-78jhTf68j&v=J5Bvy4KhIs0
@agalazis
agalazis / install.sh
Created July 20, 2016 22:39 — forked from vodolaz095/install.sh
Little script to help me installing Fedora 23 linux on my home PCs (comment lins you do not need)
#!/bin/sh
echo "Start SSHD service"
systemctl enable sshd
systemctl start sshd
echo "Remove junky programs i hate"
dnf -y remove clipit asunder gnomebaker lxmusic gnumeric osmo pidgin xpad
echo "Upgrade system"