Skip to content

Instantly share code, notes, and snippets.

@phlik
phlik / jparce.js
Created March 2, 2018 14:16
converting xml to json and pulling the data out of it
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;
test
@phlik
phlik / urlRewriteReverseProxy.js
Created February 25, 2014 14:37
Simple reverse proxy in node with url rewrite.
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 January 2, 2016 04:29
One of my many attempts to create behavior like a maybe monad in javascript.
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) {
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 January 2, 2016 04:29
Simple script to help others understand how "this" works.
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 January 6, 2013 05:20
Showing a way to make a clone of a object in javascript
<html>
<body>
<div id="con"></div>
</body>
</html>
@phlik
phlik / StringReplacementTest.js
Created May 25, 2012 17:43
finding a good way to replace values in a string.
/**
* 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;