Skip to content

Instantly share code, notes, and snippets.

View alvises's full-sized avatar

Alvise Susmel alvises

View GitHub Profile
@alvises
alvises / gist:10652679
Last active August 29, 2015 13:59
Insert document in posts collection
db.posts.insert({
title: "A MongoDB article",
content: "...",
author: {
name: "Alvise Susmel",
email: "alvise@poeticoding.com"
},
tags: ["mongodb", "nosql"]
});
@alvises
alvises / gist:10675052
Created April 14, 2014 19:08
insert for loop
for(i=0; i < 10; ++i) {
db.posts.insert({
_id: i,
title: "Article number "+i
});
}
#import "PopOverTestowyViewController.h"
#import "FPPopoverController.h"
-(IBAction)otwieramPopover:(id)sender{
//SAFE_ARC_RELEASE(popover); popover=nil;
//You have set "testController" as the identifier of your PopOverTestowyViewController in storyboard
PopOverTestowyViewController *mojController=[self.storyboard instantiateViewControllerWithIdentifier:@"testController"];
//mojController.delegate = self;
FPPopoverController *popover=[[FPPopoverController alloc]initWithViewController:mojController];
def import
params[:import]
begin
Learner.import(params[:file], current_user)
rescue Exception => e
render json: e and return
end
redirect_to groups_path, notice: "Successfully imported!"
end
@alvises
alvises / save_load_cookies.js
Created September 16, 2015 16:09
Save and Load cookies in a CasperJS script
var fs = require('fs');
function saveCookies(cookiesPath) {
var cookies = JSON.stringify(phantom.cookies);
fs.write(cookiesPath, cookies, 644);
}
function loadCookies(cookiesPath) {
var data = fs.read(cookiesPath);
phantom.cookies = JSON.parse(data);
}
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;
@alvises
alvises / app.ex
Last active March 14, 2018 09:15
GenStage and twitter stream
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)
@alvises
alvises / supervised_genstages.ex
Created September 15, 2016 13:30
supervised genstages
{: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]
@alvises
alvises / setup.ex
Created September 15, 2016 16:32
supervised genstage, producer, producer_consumer, consumer
{: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])]
@alvises
alvises / index.html
Last active September 16, 2016 15:52
Need a GeoIP Service? Build Your Own One with NodeJS and MongoDB
<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(){