Skip to content

Instantly share code, notes, and snippets.

@anvaka
anvaka / RedditsMine
Created February 24, 2012 18:35
Gist to mine all reddits from Reddit.com for node.js and MongoDb. Complies with reddit policy 1 request per 2 seconds.
var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db;
http = require('http'),
var server = new Server('localhost', 27017, {auto_reconnect: true}),
db = new Db('redditDb', server),
options = {
host: 'www.reddit.com',
@anvaka
anvaka / gist:1941011
Created February 29, 2012 13:53
Extract related subreddits from subreddit description.
import re
from models import RedditInfo
from google.appengine.ext.db import BadValueError
reLink = re.compile('/r/[a-zA-Z0-9_-]+', re.I)
def parseRedditLinks(text, exclude):
if text is not None:
return sorted(set([match.lower() for match in reLink.findall(text) if match.lower != exclude]))
@anvaka
anvaka / basic.html
Created September 18, 2012 01:34
Imagine perfect vew...
<!-- view -->
<div id='userTemplate' data-model='Domain.User'>
<div><b>First Name:</b> <%= firstName %></div>
<div><b>Last Name:</b> <%= lastName %></div>
<div><b>Age:</b> <%= age %></div>
</div>
<script>
// view model
View.UserView = inherit(BaseView, {
@anvaka
anvaka / gist:3815296
Created October 1, 2012 23:59
JavaScript Function Serialization
function functionReplacer(key, value) {
if (typeof(value) === 'function') {
return value.toString();
}
return value;
}
function functionReviver(key, value) {
if (key === "") return value;
@anvaka
anvaka / fsm.js
Created November 15, 2012 21:55
Creating Finite State Machines with VivaGraph.js
/*******************************************
* Usage:
*
* var fsm = new FiniteStateMachine(),
*
* fsm.from('state1')
* .goTo('state2').when(regex1)
* .goTo('state3').when(regex2);
* fsm.from('state2')
* .goTo('state2').when(regex2);
@anvaka
anvaka / gist:4108943
Created November 19, 2012 04:22 — forked from Restuta/gist:4108845
BDD syntax example
[Feature]
public class Tool_usage
{
[Scenario]
public void Use_new_tool()
{
// Can you do this?
Tool tool = default(Tool);
"Given I created a new tool" =>
{
@anvaka
anvaka / buildObjectGraph.js
Created November 20, 2012 21:48
Graph for internal JS objects call
function buildObjectCallGraph(obj, timeOutId) {
if (typeof Viva === 'undefined') {
if (!timeOutId) {
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.setAttribute('src', 'https://raw.github.com/anvaka/VivaGraphJS/master/dist/vivagraph.min.js');
script.setAttribute("type","text/javascript");
head.appendChild(script);
}
var timeOutId = setTimeout(function() {
forEachUnlinkedNode : function (nodeId, callback, oriented) {
var graph = this,
node = graph.getNode(nodeId),
linkedNodeId,
currentNodeId;
if (node && typeof callback === 'function') {
var linkedNodes = {};
graph.forEachLinkedNode(nodeId, function (node) { linkedNodes[node.id] = true; }, oriented);
@anvaka
anvaka / quine1.js
Last active December 12, 2015 10:18
Just having fun... This function prints itself to the console.
(function () {
var arr = ["(function () {", "var arr = [", "arr[1] += arr.map(function(x) { return String.fromCharCode(0x22) + x + String.fromCharCode(0x22); }).join(', ') + '];';", "arr.forEach(function(x) { console.log(x); });", "}())"];
arr[1] += arr.map(function(x) { return String.fromCharCode(0x22) + x + String.fromCharCode(0x22); }).join(', ') + '];';
arr.forEach(function(x) { console.log(x); });
}())
// what needs to be changed in this code, to satsify requirements below:
function () {
function foo() {
var a = 42,
b = function () { console.log('hi'); };
}
// a and b should be available in this scope (but not the outter)
// No other modifications to this scope are allowed
function bar() {
// could use a, b.