Skip to content

Instantly share code, notes, and snippets.

@phlik
phlik / jparce.js
Created Mar 2, 2018
converting xml to json and pulling the data out of it
View jparce.js
var _ = require('underscore');
var x2js = require('xml2js');
function traverseJson(path, node){
function getElement(n, p){
var t = n[p];
if(_.isUndefined(t)){
return n['$'][p];
}
return _.isArray(t) ? t[0] : t;
@phlik
phlik / urlRewriteReverseProxy.js
Created Feb 25, 2014
Simple reverse proxy in node with url rewrite.
View urlRewriteReverseProxy.js
var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
http.createServer(function(req, res){
if(/^\/api/.test(req.url)){
req.url = req.url.replace(/^\/api/, "");
proxy.web(req, res, {target:'http://localhost:7889'});
} else {
@phlik
phlik / mabyInJavascript.js
Last active Jan 2, 2016
One of my many attempts to create behavior like a maybe monad in javascript.
View mabyInJavascript.js
var maybe = function(item) {
var __internal = item;
this.result = function(accessor, __default) {
if (!__internal) {
return new type(accessor).is_func() ? __default : accessor;
}
return new type(accessor).is_func() ? accessor(__internal) : __internal;
};
this.select = function(accessor) {
View simpleLocalization.js
var termDictionay = {"first":'text goes here'};
var localization = (function(terms) {
var _terms = terms;
var retVal = {
stampValues : function (template, replacements) {
/// <summary>Replaes tokens in a template string</summary>
/// <param name="template">string that is to have values replaced in</param>
@phlik
phlik / funWithThis.js
Last active Jan 2, 2016
Simple script to help others understand how "this" works.
View funWithThis.js
window.name = 'windo';
function Taco(name) {
this.name = name;
var nameCool = name + ' cool';
function PrintNameThis() {
console.log(this.name);
}
this.showTheWindowScope = function() {
@phlik
phlik / deepCopy.html
Created Jan 6, 2013
Showing a way to make a clone of a object in javascript
View deepCopy.html
<html>
<body>
<div id="con"></div>
</body>
</html>
@phlik
phlik / StringReplacementTest.js
Created May 25, 2012
finding a good way to replace values in a string.
View StringReplacementTest.js
/**
* User: ehouston
*/
var _ = require('underscore');
var localSub = function (text, data) {
// TODO: Implement more efficient replace.
// Loop through all keys and replace the data.
var result = text;
You can’t perform that action at this time.