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
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
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
<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
-(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
.site-header { | |
background: white !important; | |
background-color: white !important; | |
} |
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 Coinbase.Client do | |
use WebSockex | |
@url "wss://ws-feed.pro.coinbase.com" | |
def start_link(products \\ []) do | |
{:ok, pid} = WebSockex.start_link(@url, __MODULE__, %{}) | |
subscribe(pid, products) | |
{:ok, pid} | |
end |
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
lazy_csv_fn = fn -> | |
File.stream!("large.csv") | |
|> Stream.map(&String.trim(&1)) | |
|> Stream.map(&String.split(&1, ",")) | |
|> Stream.filter(fn | |
["Timestamp" | _] -> false | |
[_, "NaN" | _] -> false | |
[timestamp | _] -> | |
true | |
end) |> Enum.find(fn |
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
docker container run -p 8000:80 nginx |
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 Example do | |
use GenServer | |
def start_link(_) do | |
GenServer.start_link __MODULE__, :ok, [] | |
end | |
def init(:ok) do | |
{:ok, []} | |
end |