Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am appplemac on github.
  • I am alexey_ch (https://keybase.io/alexey_ch) on keybase.
  • I have a public key whose fingerprint is 7F3A CFBB 4647 F569 A9B1 7F36 04BE 4BEB 964A 0267

To claim this, I am signing this object:

@appplemac
appplemac / space.rb
Created Jun 11, 2013
One-liner for getting free space on current machine's mounted filesystems
View space.rb
`df`.split("\n").map {|line| line.split(" ")[3].to_i}[1...-1].inject(:+) / (1024*1024)
@appplemac
appplemac / weather.rb
Last active Dec 18, 2015
Quick and dirty script for getting current weather in text mode with Forecast.io API.
View weather.rb
#!/usr/bin/env ruby
# encoding: utf-8
require 'forecast_io'
Forecast::IO.api_key = "your_forecast.io_api_key"
# Position for Campus Nord UPC
weather = Forecast::IO.forecast(41.387885, 2.112808, time: Time.now.to_i, params: { units: 'si' })
current = weather[:currently]
temp = current[:temperature]
precip = current[:precipIntensity]
@appplemac
appplemac / morris-pratt.cpp
Created May 31, 2013
A simple C++ implementation of Morris-Pratt search algorithm
View morris-pratt.cpp
#include <vector>
#include <iostream>
using namespace std;
void prepare(const vector<int>& x, int m, vector<int>& mpnext) {
int i = 0;
int j = -1;
mpnext[0] = -1;
while (i < m) {
while (j>-1 and x[i] != x[j]) j = mpnext[j];
View vectorsum_parallel.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#define MAX 10000
#define NTHREADS 10
View counting_inversions.cpp
#include <iostream>
#include <vector>
using namespace std;
int merge(vector<int>& v, int left, int delim, int right) {
int inv_counter = 0;
int i = left;
int j = delim;
int k = 0;
vector<int> aux(right-left+1);
@appplemac
appplemac / pr1.java
Last active Dec 17, 2015
JDBC stuff
View pr1.java
/* Imports de la classe */
import java.sql.*;
import java.io.*;
/* Capa de Control de Dades */
class CtrlDadesPublic extends CtrlDadesPrivat {
public ConjuntTuples consulta(Connection c, Tuple params) throws BDException {
try {
ConjuntTuples ct = new ConjuntTuples();
@appplemac
appplemac / ci.rb
Last active Dec 14, 2015
CI, condensator charge calculus
View ci.rb
C = 100e-12
R = 10e3
T = 10e-9
const = Math::E**(-T/(R*C))
vc = 5*(1-const)
vc1 = vc * const
1000000.times do
vc = 5 - ((5-vc1)*const)
vc1 = vc*const
end
@appplemac
appplemac / gist:4182062
Created Dec 1, 2012
World implementation
View gist:4182062
void World::migrate_central(Region r, int h, int spec_id) {
}
void World::migrate_periferic(Region r, int h, int spec_id) {
}
@appplemac
appplemac / gist:3867062
Created Oct 10, 2012
Incorrecte en C++
View gist:3867062
#include <vector>
...
vector v;
vector<vector> mat;
...