Skip to content

Instantly share code, notes, and snippets.

View ianliu's full-sized avatar

Ian Liu Rodrigues ianliu

  • moray.ai
  • Campinas, Brazil
  • 02:19 (UTC -03:00)
  • LinkedIn in/ianliu88
View GitHub Profile
@ianliu
ianliu / csv
Last active March 27, 2019 14:55
Simple script to process CSV files in a streaming fashion, with correct escaping of commas in values
#!/usr/bin/env python3
import csv
import sys
import argparse
parser = argparse.ArgumentParser(description=(
'Process CSV files in a streaming fashion. By default, assumes there is a'
' header row and columns are selected by name. If the -i flag is passed,'
' columns are selected by indices starting from 0 and no header row is'
@ianliu
ianliu / vtable-vs-switch.c
Last active August 29, 2015 14:02
Program to compare performance of VTable versus Switch in a simple program
/* Compile with: gcc -O3 vtable-vs-switch.c -o vtable-vs-switch */
/* Execute: time ./vtable-vs-switch switch */
/* time ./vtable-vs-switch vtable */
/* Execution time should last less than a minute. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static FILE *output;
@ianliu
ianliu / rock-paper-scissors.py
Created April 9, 2014 17:40
Rock, paper, scissors!
from random import randint
CHOICES = ['rock', 'paper', 'scissors']
INITIALS = [c[0] for c in CHOICES]
class Player(object):
def __init__(self, name):
self.name = name
def get_name(self):
@ianliu
ianliu / Makefile
Created December 5, 2013 10:55
A simple Makefile for cmake builds!
all clean: build build-opt
@$(MAKE) -s -C build $@
@$(MAKE) -s -C build-opt $@
build:
mkdir -p $@ ; cd $@ && \
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=Yes \
-DCMAKE_BUILD_TYPE=Debug ..
build-opt:
@ianliu
ianliu / checker.py
Created August 1, 2013 12:51
Generates a checker image in a binary format, for the ERAD-SP 2013 challange (http://erad.dc.ufscar.br/desafio.html)
import sys
from struct import pack
def usage():
sys.stderr.write("Usage: %s -w WIDTH -h HEIGHT [-s SIZE]\n" % \
(sys.argv[0], ))
sys.stderr.write(" -w WIDTH Image width\n")
sys.stderr.write(" -h HEIGHT Image height\n")
sys.stderr.write(" -s SIZE Size of the checkers (default 100)\n")
sys.exit(1)
@ianliu
ianliu / u
Created July 18, 2013 03:07
YouTube and FlashPlayer nevermore. When a video does not work with HTML5 in YouTube, click "Share > Embed", copy the text and execute "u" script. Voila!
#!/bin/bash
#
# Copyright (C) 2013 Ian Liu Rodrigues <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
// compile with: gcc atomic-sum.c -lpthread
#define __STDC_FORMAT_MACROS
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <inttypes.h>
uint64_t sum = 0;
static int n_threads = 4;
X = 8.95
xx = [1.4, 2.3, 4.0, 5.9, 10.0, 10.1]
n = len(xx)
ff = [x*x for x in xx]
ww = [1.0 for i in range(n)]
for i in range(n):
for j in range(n):
if i != j:
@ianliu
ianliu / interpol.f90
Last active December 14, 2015 23:09
Interpolador de ???
PROGRAM interpol
Implicit none
double precision :: Y, X = 8.95
double precision :: s1, s2, p
integer :: n = 6, i, j
double precision,allocatable,dimension(:) :: xx, ff, ww
allocate(xx(n))
allocate(ff(n))
@ianliu
ianliu / FindC99.cmake
Created March 13, 2013 21:08
CMake module for searching for a compatible C99 compiler.
# - Finds C99 standard support
# This internally calls the check_c_source_compiles macro to determine the
# appropriate flags for a C99 standard compilation.
#=============================================================================
# Copyright 2013 Ian Liu Rodrigues <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or