Skip to content

Instantly share code, notes, and snippets.

@appplemac
appplemac / keybase.md
Created April 18, 2015 18:06
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 June 11, 2013 11:24
One-liner for getting free space on current machine's mounted filesystems
`df`.split("\n").map {|line| line.split(" ")[3].to_i}[1...-1].inject(:+) / (1024*1024)
@appplemac
appplemac / weather.rb
Last active December 18, 2015 01:29
Quick and dirty script for getting current weather in text mode with Forecast.io API.
#!/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 16:20
A simple C++ implementation of Morris-Pratt search algorithm
#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];
#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
#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 December 17, 2015 10:59
JDBC stuff
/* 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 December 14, 2015 01:09
CI, condensator charge calculus
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 December 1, 2012 12:40
World implementation
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 October 10, 2012 17:23
Incorrecte en C++
#include <vector>
...
vector v;
vector<vector> mat;
...