This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)presentPopoverFromView:(UIView *)fromView | |
onModalViewController:(UIViewController*)modalViewController { | |
[self presentPopoverFromView:fromView]; | |
//converting the origin of the popover from the old parent view to the new modal view | |
self.origin = [modalViewController.view convertPoint:self.origin fromView:_parentView]; | |
//the new parent view is the modal view | |
[self.view removeFromSuperview]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<HTML> | |
<head> | |
<title>GeoIP test</title> | |
<script src="http://geoip.poeticoding.com/geoip.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<div id="details">Loading...</div> | |
</body> | |
<script> | |
var geoip = new GeoIP(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GeoIP(forcedIP) { | |
var locateUrl = "http://geoip.poeticoding.com/locate"; | |
//locate function, success or fail callbacks will be triggered | |
//once the request to the server is finished | |
this.locate = function(successCallback,failCallback) { | |
var xhr = new XMLHttpRequest(); | |
if(forcedIP) locateUrl += "?ip="+forcedIP; | |
xhr.open("GET", locateUrl, true); | |
xhr.timeout = 60000; | |
xhr.onload = function (e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/locate', function(req, res) { | |
//getting the ip of the client from the request headers or remoteAddress | |
var ip = req.param("ip"); | |
ip = ip || req.headers['x-forwarded-for'] || req.connection.remoteAddress; | |
var net = ip.split(".").slice(0,3).join(".")+".0"; //aaa.bbb.ccc.0 | |
mongodb.connect("mongodb://127.0.0.1:27017/poetic_geoips",function(err,db){ | |
if(err) throw err; | |
var ips = db.collection("ips"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var mongodb = require('mongodb'); | |
var app = express(); | |
//ENABLE CORS | |
app.all('*', function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "X-Requested-With"); | |
next(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>MaxMind GeoIP test</title> | |
<script type="text/javascript" src="//js.maxmind.com/js/apis/geoip2/v2.0/geoip2.js"></script> | |
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> | |
</head> | |
<body> | |
<h1>Loading...</h1> | |
<script type="text/javascript"> | |
$(document).ready(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:ok, p} = Producer.start_link | |
workers_num = 20 | |
workers = Enum.map(1..workers_num, fn (n)-> | |
worker(ProducerConsumer, [worker_name(n)], id: n) | |
end) | |
worker_names = Enum.map 1..8, &worker_name/1 | |
#consumer subscribes to the producer names passed | |
consumers = [worker(Consumer, [worker_names])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:ok, p} = Producer.start_link | |
children = [ | |
worker(ProducerConsumer, [:pc_1], id: 1), | |
worker(ProducerConsumer, [:pc_2], id: 2) | |
] | |
{:ok, sup} = Supervisor.start_link children, strategy: :one_for_one | |
{:ok, consumer} = Consumer.start [:pc_1, :pc_2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Twitter do | |
def start(_type, _args) do | |
import Supervisor.Spec | |
workers = [ | |
worker(Twitter.Producer, ["#Rio2016"]), | |
worker(Twitter.Consumer, [], id: 1), | |
worker(Twitter.Consumer, [], id: 2), | |
worker(Twitter.Consumer, [], id: 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url, contentType; | |
casper.start(....) | |
//download time | |
//waitForResource because sometime the server is redirecting multiple time | |
//the browser, so we need the final url to download it as pdf (or render it as html) | |
.waitForResource(function testResource(resource) { | |
console.log("resource: "+resource.status+" : "+resource.contentType+" : "+resource.url); | |
if(resource.status == 200) { | |
url = resource.url; |