Skip to content

Instantly share code, notes, and snippets.

View palcu's full-sized avatar
🚒
Responding to a pager alert

Alex Palcuie palcu

🚒
Responding to a pager alert
View GitHub Profile
@palcu
palcu / script.php
Created April 27, 2017 13:37
legislatie.just.ro PHP script
<?php
// First request for the token
$client = new SoapClient("http://legislatie.just.ro/apiws/FreeWebService.svc?wsdl");
$response = $client->GetToken();
var_dump($response);
// Second request for getting the actual data
$params = array(
@palcu
palcu / CkanClient.java
Last active August 29, 2016 19:46
CKAN Java create/update a resource
import java.io.File;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
In [25]: session = requests.Session()
In [27]: data = {'username':'palcuiealex', 'password':"bla"}
In [28]: url
Out[28]: 'https://infoarena.ro/login'
In [29]: session.post(url, data=data)
Out[29]: <Response [200]>
@palcu
palcu / ckan.conf
Created June 2, 2016 13:12
data.gov.ro nginx config
# BEWARE
# There are two parts, first port 80 and then port 443
# We have 2 needs: serving everything that we can on HTTP (this means we redirect most of the requests from HTTPS)
# Serving the login page and logged in people from HTTPS
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache:30m max_size=250m;
proxy_temp_path /tmp/nginx_proxy 1 2;
server_tokens off;
server {
@palcu
palcu / main.cpp
Created April 10, 2016 22:58
Advice C++ InfoClock
// Includes all headers
#include <bits/stdc++.h>
// Don't be afraid to use constants
const int N = 1024;
void do_not_use_endl() {
vector<int> primes {2, 3, 5, 8, 11};
// Let's tail -f the output file
@palcu
palcu / script.py
Created March 16, 2016 13:04
Mapper for Disqus
import csv
urls = []
with open('links.csv') as stream:
for line in stream:
url = line.strip()
if 'http' in url and 'https' not in url:
better_url = url.replace('http', 'https', 1) # replace only first occurence
urls.append([url, better_url])
import math;f=open('i');r=f.readline
for _ in range(1,int(r())+1):
m=[];s=b=0
for i in range(int(r())):m.append([1 if j=='#' else 0 for j in r()]);s+=sum(m[i])
a=int(math.sqrt(s))
while not filter(None,m[0]):m.pop(0)
l=[i for i,x in enumerate(m[0]) if x];x=l[0];y=l[-1]
for v in m:
if a!=sum(v[x:y+1]):break
else:b+=a
import math
f = open('input.in')
cases = int(f.readline())
for case in range(cases):
m = [ ]
lines = int(f.readline())
# read and convert the matrix
@palcu
palcu / enumerate.py
Last active December 29, 2015 11:49
# get left right indices
l = [i for i, x in enumerate(m[0]) if x]
left = l[0]
right = l[-1] + 1
@palcu
palcu / slices.py
Last active December 29, 2015 11:49
# sum up the portion of the matrix where the square
# should be
new_sum = 0
for line in range(sum_on_a_line):
if sum_on_a_line != sum(line[left : right]):
break
else:
new_sum += sum_on_a_line