Skip to content

Instantly share code, notes, and snippets.

View shimondoodkin's full-sized avatar

Shimon Doodkin shimondoodkin

View GitHub Profile
@shimondoodkin
shimondoodkin / goals.md
Last active January 9, 2023 08:17
plain vanilla node.js intro tutorial to learn a lot in the shortest time.

The plan is to take a simple nodejs server. and add to it simple file serving capabilities. also to have a custom responce to a certien url. to be able to make a simple api in addition of serving files.

goals:

  • to learn read the documentation
  • to understand the whole concept
  • to use some api for hands on expirience
  • streach goal: learn basic npm usage.
@shimondoodkin
shimondoodkin / rtconsole.js
Last active December 18, 2015 22:59
realtime console in nodejs. node.js enables to integrate tooling into the application. for a quick tab refresh to build front end tooling.
//functions.js
//f.rtconsole('generate.py build','/mnt/hda1/www/bursa/public/charts/generate.py',['build'],req,res,purl)
var tempstreams={};
function rtconsole(streamname,command,command_args,req,res,purl)
{
//var streamname='genbuild';
//if(global.tempstreams===undefined)tempstreams={}; // ceate some global to store text and status
if(tempstreams[streamname]===undefined)tempstreams[streamname]={};
var tempstream=tempstreams[streamname];
if(tempstream.text===undefined)tempstream.text="";
@shimondoodkin
shimondoodkin / datefunctions.js
Last active December 18, 2015 21:38
date functions i use
Date.prototype.isValid = function() {
if ( Object.prototype.toString.call(this) !== "[object Date]" )
return false;
return !isNaN(this.getTime());
}
////////////
@shimondoodkin
shimondoodkin / Taskbar.js
Last active January 21, 2017 16:21
qooxdoo desktop taskbar class. modify qx.Class.define("charts.Taskbar", ... to your choice of class prefix
//TASKBAR CLASS
/**
* This class provides some well known operating system like taskbar
* behaviours. To every added window a toggle button is attached, that
* can switch the window between maximized and minimized state.
*
* *Example*
*
* Here is a little example of how to use the widget.
the basics of programming with callbacks:
structure:
function simple1(cb) // the last argument is callback function
{
if(cb)return cb();// the return is required to prevent continuation of the function.
// the if(cb) is optional and it is to enable to omit the callback in rare cases.
// it is usually useful in api functions.
}
@shimondoodkin
shimondoodkin / todo list in facebook.tamper.js
Last active December 17, 2015 09:58
in chrome, add Tampermonkey plugin. add new script. copy paste to new script
// ==UserScript==
// @name todo list in facebook
// @namespace http://kodtov.com
// @version 0.1
// @description adds a todo list in top of facebook
// @include *facebook.com*
// @copyright 2013, Shimon Doodkin
// ==/UserScript==
// tinyxhr by Shimon Doodkin - licanse: public doamin - https://gist.github.com/4706967
@shimondoodkin
shimondoodkin / gist:5142644
Created March 12, 2013 12:53
node.js reverse proxy at end of express. to make post commands work must remove bodyparser and mothod override. use body parser as middleware of app.get command.
// this is not a main file the main file is opchart.js
var express = require('express')
// , routes = require('./routes')
// , user = require('./routes/user')
, path = require('path');
sessionStore=false //defined on first time it could be catched from a request
app = express();//global
@shimondoodkin
shimondoodkin / tinyxhr.js
Last active September 19, 2023 18:10
tiny xhr snippet to do XMLHttpRequest
// tinyxhr by Shimon Doodkin - licanse: public doamin - https://gist.github.com/4706967
//
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) });
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) },'POST','value1=1&value2=2');
// tinyxhr("http://site.com/ajaxaction.json",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data); console.log(JSON.parse(data)) },'POST',JSON.stringify({value:1}),'application/javascript');
// cb - a callback function like: function (err,data,XMLHttpRequestObject){ if (err) throw err; }
//
function tinyxhr(url,cb,method,post,contenttype)
{
@shimondoodkin
shimondoodkin / merge_arrays.js
Created February 1, 2013 15:53
this awesome piece of JavaScript is written by me, by rewriting merge-strings function to use array elements instead of chars. licence: 2 close bsd/public domain
///////////////////////////merge arrays////// wrote by Shimon Doodkin/////////
/*
test mergin two arrays with common merging points
merge
[1,10:55] ,
[2,10:55] ,
[3,10:55]
/*
These next two functions work together to lock down bbPress forums based on PMPro membership level.
Check that the current user has access to this forum. Be sure to update the $restricted_forums array based on your needs.
*/
function pmpro_check_forum()
{
global $current_user;
/*