Skip to content

Instantly share code, notes, and snippets.

ntanya

Block or report user

Report or block ntanya

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ntanya
ntanya / gist:816cba067f0e0dccc524
Last active Nov 12, 2019
Python script to check HTTP status and redirect chains
View gist:816cba067f0e0dccc524
import requests
def get_status_code(url):
try:
r = requests.get(url)
print "Processing " + url
if len(r.history) > 0:
chain = ""
code = r.history[0].status_code
@ntanya
ntanya / gist:3717461
Created Sep 13, 2012
Python csv with twitter api lookups
View gist:3717461
import csv
import urllib2
import json
import re
def findID(str):
# extracts the status ID from teh following string example:
# "http://twitter.com/IBPTravels/statuses/75907873892339712"
matchObj = re.match('(.)+statuses\/(\d+)', str, re.I)
return matchObj.group(2)
@ntanya
ntanya / node1
Created Jun 26, 2012
Node.js data sharing between server and client
View node1
//Client side
app.get('/trends', function(req, res){
twitterProcessor.getTrends( function(error, trendData){
res.render('trends.jade',{ locals: {
trends:trendData // here's the data you pass to client
}
});
});
});
@ntanya
ntanya / mr2
Created Jun 26, 2012
Map Reduce
View mr2
var map = function(){
emit(this.tag, {tag_date: this.tag_date, count:this.count});
}
var reduce = function(key, values){
var obj = {value: []};
for(var i in values){
obj.value.push({tag_date:values[i].tag_date, count:values[i].count});
}
return obj;
@ntanya
ntanya / mr1
Created Jun 26, 2012
Map Reduce
View mr1
coll.mapReduce(
//map
function(){
emit(this.tag, {tag_date: this.tag_date, count:this.count});
},
// reduce
function(key, values){
var obj = {value: []};
for(var i in values){
obj.value.push({tag_date:values[i].tag_date, count:values[i].count});
@ntanya
ntanya / get3
Created Jun 8, 2012
GET with node
View get3
response.on('end', function(){
var dataObj = JSON.parse(completeResponse);
var saveObj = {
id: dataObj["id"],
created_at: dataObj["created_at"],
description: dataObj["description"],
followers_count: dataObj["followers_count"],
@ntanya
ntanya / get2
Created Jun 8, 2012
GET with node
View get2
var completeResponse = "";
request.on('response', function (response) {
response.on('data', function (chunk) {
//res.send("data: " + chunk);
completeResponse += chunk;
});
@ntanya
ntanya / get1
Created Jun 8, 2012
GET with node
View get1
app.get('/', function(req, res){
var user = "twitterapi;
var completeResponse = "";
var options = {
host: 'api.twitter.com',
port: 80,
path: '/1/users/show.json?screen_name=' + user
};
View upload3
app.post('/', function(req, res){
var temp_path = req.files.uploadfile.path;
var save_path = './public/images/' + req.files.uploadfile.name;
fs.rename(temp_path, save_path, function(error){
if(error) throw error;
fs.unlink(temp_path, function(){
if(error) throw error;
View upload2
var express = require('express');
var fs = require('fs'); // we will need it for file uploads
var app = module.exports = express.createServer();
app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
You can’t perform that action at this time.