Skip to content

Instantly share code, notes, and snippets.

View giuscri's full-sized avatar

Giuseppe Crinò giuscri

View GitHub Profile
@giuscri
giuscri / silly.c
Last active December 23, 2015 22:59
silly code.
#include <stdio.h>
int
main(int argc, char* argv[])
{
int single_byte = getchar();
while (single_byte != EOF) {
single_byte = getchar();
printf("getchar() != EOF is %d.\n", single_byte != EOF);
@giuscri
giuscri / jennie.c
Last active December 24, 2015 04:09
Portion of a code that was broken
// That sounds working
// ...
// ...
if (y1 > y2)
printf("Date %2.2d/%2.2d/%2.2d is earlier.\n",d2,m2,y2);
else if (y1 == y2) {
if (m1 > m2)
printf("Date %2.2d/%2.2d/%2.2d is earlier.\n",d2,m2,y2);
@giuscri
giuscri / ex1_13.c
Last active December 24, 2015 04:19
Solving EX1-13 of K&R-book
#include <stdio.h>
#define IN 1 // Reading *inside* a word
#define OUT 0 // Reading *outside* a word
int
main()
{
int state = OUT;
#include <stdio.h>
#define MAXLINE 1000 // Maximum input line size
int get1line(char line[], int maxline);
void copy(char to[], char from[]);
// Print longest input line
int
main()
{
@giuscri
giuscri / <piece_of_code> .c
Created October 6, 2013 14:08
get_line_from_instream()
char * get_line_from_instream(void) {
char * line = malloc(100), * linep = line;
size_t lenmax = 100, len = lenmax;
int c;
if (line == NULL)
return NULL;
for (;;) {
c = fgetc(stdin);
@giuscri
giuscri / foo.java
Last active August 29, 2015 13:56
Evitare l'uso di classi anonime in `iterator()`
@Override
public Iterator<Giocatore> iterator() {
class IteratorOverGiocatores implements Iterator<Giocatore> {
private int currentIndex = 0;
@Override
public boolean hasNext() {
return (currentIndex < rosa.size() && !rosa.isEmpty());
}
@giuscri
giuscri / out.java
Created February 21, 2014 11:37
Unix pipes in Java
/**
* Questa classe non e' stata utilizzata davvero.
*/
public abstract class AbstractFilter implements Filter {
/*
public StringBuffer process(String in) {
return process(new StringBuffer(in));
}
public StringBuffer process(StringBuffer in);
[ x for x in [1, 2, 3] and [4, 5, 6] ] == [ 1, 2, 3, 4, 5, 6 ]
@giuscri
giuscri / hl.py
Last active August 29, 2015 14:00
@transact_ro
def get_receiver_logs(store, receiver_id, language=GLSetting.memory_copy.default_language):
receiver = store.find(Receiver, Receiver.id == receiver_id).one()
rlogs = receiver.user.access_log
return rlogs
class ReceiverLogs(BaseHandler):
#@...
def get(self):
;; triangleNumbers.asm
.text
.globl main
main:
;; Push $ra onto the stack ...
subu $sp, $sp, 4
sw $ra, 0($sp)