Skip to content

Instantly share code, notes, and snippets.

View astagi's full-sized avatar
๐Ÿ 
Working from home

Andrea Stagi astagi

๐Ÿ 
Working from home
View GitHub Profile
@astagi
astagi / newmath.go
Last active September 14, 2018 21:58
package main
import "C"
//export sum
func sum(a, b int) int {
return (a + b)
}
@astagi
astagi / _newmath.c
Last active September 14, 2018 21:58
#define Py_LIMITED_API
#include <Python.h>
#include "libnewmath.h"
PyObject *sum_wrapper(PyObject *obj, PyObject *args) {
const long a, b;
if (!PyArg_ParseTuple(args, "LL", &a, &b))
return NULL;
@astagi
astagi / main.rb
Created September 27, 2018 12:01
Try ansa gem
require 'ansa'
puts "\nโšฝ๏ธ SOCCER NEWS โšฝ๏ธ\n\n"
begin
Ansa::get_soccer_news.each do |news|
puts "๐Ÿฅ… [#{news.date.strftime("%d/%m %H:%M:%S")}] #{news.title}"
puts news.description
puts "\n"
end
@astagi
astagi / client.rb
Last active September 27, 2018 12:50
Dynamic generation
module Ansa
# ....
private
def self.generate_get_news(category, url)
define_singleton_method("get_#{category}_news") do
get_news_by_url(url)
end
end
public
@astagi
astagi / client.rb
Last active September 27, 2018 12:48
Try to use macro
module Ansa
private
# @!macro [attach] generate_get_news
# @method get_$1_news
# @!scope class
# @note This method is autogenerated
# Get news for "$1" category.
# @raise [Ansa::AnsaError] when errors occour fetching news
# @return [Array<Ansa::News>] all the news of category "$1".
def self.generate_get_news(category, url)
module Ansa
generate_get_news 'homepage', 'http://www.ansa.it/sito/ansait_rss.xml'
generate_get_news 'news', 'http://www.ansa.it/sito/notizie/cronaca/cronaca_rss.xml'
generate_get_news 'politics', 'http://www.ansa.it/sito/notizie/politica/politica_rss.xml'
generate_get_news 'world', 'http://www.ansa.it/sito/notizie/mondo/mondo_rss.xml'
generate_get_news 'economy', 'http://www.ansa.it/sito/notizie/economia/economia_rss.xml'
generate_get_news 'soccer', 'http://www.ansa.it/sito/notizie/sport/calcio/calcio_rss.xml'
generate_get_news 'sport', 'http://www.ansa.it/sito/notizie/sport/sport_rss.xml'
end
require 'yard'
require 'fileutils'
YARD::Rake::YardocTask.new do |t|
dynamic_dir = File.join('lib', 'ansa', 'docs')
dynamic_file = File.join(dynamic_dir, 'dynamic_docs.rb')
FileUtils.mkdir_p dynamic_dir
f = File.new(dynamic_file, 'w')
f.write("module Ansa")
Ansa::LINKS.each do |category, url|
@astagi
astagi / remove_all_sessions.py
Created December 18, 2018 11:07
Remove all sessions from Django
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'ares.settings'
import django
django.setup()
import datetime
from django.conf import settings
from django.contrib.auth import logout
@astagi
astagi / phantomjs_install.sh
Last active April 15, 2019 20:53 — forked from ianchen06/phantomjs_install.sh
How to install PhantomJS on CentOS/RHEL
yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -xjvf ~/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 --strip-components 1 /opt/phantomjs/
sudo yum install libffi-devel openssl-devel
pip install pyopenssl pyasn1
pip install requests[security]
from createsend import Subscriber
from createsend.createsend import BadRequest
class CampaignMonitorException(Exception):
pass
class CampaignMonitorListSubscriber():