Skip to content

Instantly share code, notes, and snippets.

View proudlygeek's full-sized avatar
🍕

Gianluca Bargelli proudlygeek

🍕
View GitHub Profile
int main () {
pthread_t thread1, thread2;
char message1[] = "I am thread 1";
char message2[] = "I am thread 2";
int numero = 102;
int iret1, iret2;
pthread_attr_t attr;
pthread_attr_init(&attr);
def split_pages(currentpage, totalpages):
"""
Splits a certain number of pages into several
lists; for example, if the current page is 31 on a total of 115
pages the return tuple is:
([1, 2, 3, 4], [27, 28, 29, 30, 31, 32, 33, 34], [112, 113, 114, 115])
"""
# Check if currentpage is less than the total
if currentpage > totalpages:
@proudlygeek
proudlygeek / order.py
Created January 11, 2011 11:54
Lo script prende in input il file values.in
# -*- coding: utf-8 -*-
"""
Order
~~~~~
Determina il numero minimo di mosse per ordinare un
array di elementi sapendo che è possibile spostare un
qualsiasi elemento in cima o in fondo.
/* Defines a function in the prototype of all
* functions:
*
* Usage: Function.method('add', add);
* var f = function() {};
* f.add(1,2);
*/
Function.prototype.method = function (name, func) {
// Creates a new property; this points to the Function object.
7
20
40
9
11
8
4
2
31
@proudlygeek
proudlygeek / jquery-tests.js
Created October 5, 2011 20:01
Taskspeed tests
window.tests = {
"make": function(){
for(var i = 0; i<250; i++){
$("<ul class='fromcode'><li>one</li><li>two</li><li>three</li></ul>")
.attr("id", "setid" + i)
.appendTo("body");
}
return $("ul.fromcode").length;
},
@proudlygeek
proudlygeek / chatty.rb
Created February 8, 2012 07:13
Ruby Chat Server
# encoding: utf-8
require 'socket'
class Chatty
def initialize
@clients = []
end
@proudlygeek
proudlygeek / gist:1766748
Created February 8, 2012 08:20
Basic Ruby Chat
# encoding: utf-8
require 'socket'
class Chatty
def initialize
@clients = []
end
@proudlygeek
proudlygeek / toys.rb
Created February 18, 2012 14:05 — forked from lucapette/toys.rb
methods to create toys arrays and hashes (using modules)
module MonkeyIrb
def self.included(base)
# Monkey-patching Array
class << Array
def toy(n=10, &block)
block_given? ? Array.new(n, &block): Array.new(n) { |i| i + 1 }
end
end
@proudlygeek
proudlygeek / StopListsManager
Created February 22, 2012 16:48
regex for decamelcasing things
preg_split('/(?=[A-Z])/',$str);