Skip to content

Instantly share code, notes, and snippets.

View joelthelion's full-sized avatar

Joel Schaerer joelthelion

  • Bioclinica
  • Lyon, France
View GitHub Profile
@joelthelion
joelthelion / gist:102413
Created April 27, 2009 09:35
Parse a string in C++
template<class ElementType>
std::vector<ElementType> parse_string(std::string str,char delim)
{
std::istringstream ss(str);
std::string token;
std::vector<ElementType> result;
while (getline(ss,token,delim))
{
std::istringstream token_parser(token);
ElementType value;
@joelthelion
joelthelion / buzz.py
Created October 27, 2009 10:08
This is a simple script to identify the newest trends on a set of RSS feeds. It requires Mark Pilgrim's feedparser.
#!/usr/bin/env python
# coding=utf8
#Identify the newest trends
from __future__ import division
import os
import re
import cPickle
import time
import sys
#perform histogram equalization with numpy, without explicitly computing the histogram
#im is a numpy array, of any dimension
im2 = numpy.sort(im.ravel()).searchsorted(im)
@joelthelion
joelthelion / HelloDartTest.dart
Created November 22, 2011 13:01 — forked from munificent/HelloDartTest.dart
Dart Compilation
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Simple test program invoked with an option to eagerly
// compile all code that is loaded in the isolate.
// Compiled using frog, the in-progress self-hosted compiler:
// dart/frog$ ./frogsh --out=hello.js --compile-only samples/hello.dart
class HelloDartTest {
static testMain() {
@joelthelion
joelthelion / get_liked.py
Created December 6, 2011 12:19
Get liked items on reddit
#!/usr/bin/env python2
# coding: utf-8
import json
import gzip
from StringIO import StringIO
from getpass import getpass
# Install http://docs.python-requests.org/en/latest/
import requests
@joelthelion
joelthelion / languages.py
Created December 7, 2011 21:22
What language do the best AI programmers use?
#!/usr/bin/env python2
# coding: utf-8
import json
a=json.load(open("ranking_json.php")) # get at http://aichallenge.org/ranking_json.php
print a.keys()
#print a["values"][8]
#print a["values"][8][18] # skill
#print a["values"][8][22] # games
#print a["values"][8][7] # language
@joelthelion
joelthelion / quicksave.py
Last active December 15, 2015 07:59
Simple script for quick and dirty backups
#!/usr/bin/env python3
# coding: utf-8
# Copyright Joel Schaerer, 2013. Licensed under the GPL, version 3
from datetime import datetime
from sys import argv
import os, shutil
from itertools import count
""" Simple script for quick and dirty backups.
@joelthelion
joelthelion / weather_notifications.py
Created March 27, 2013 20:27
Simple prototype for weather notifications based on the Yahoo! weather API. Needs support for multiple locations and a way for people to subscribe.
#!/usr/bin/env python3
# coding: utf-8
import yweather
import shelve
import datetime
from conditions import conditions
def send_plain_mail(subject, body, from_mail, to):
import smtplib
@joelthelion
joelthelion / gist:7d4d4b44120607b63035
Created July 9, 2015 23:18
Streaming JSON array downsampler written in (probably bad) Haskell
import Data.JsonStream.Parser
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Aeson.Types as AT
import qualified Data.Aeson.Encode as AE
import Pipes
import qualified Pipes.Prelude as P
import System.IO (isEOF, stdin)
import System.Random
#!/bin/python3
""" Optimize redundant predictions on hypermind """
import numpy
from collections import namedtuple
from itertools import product
Proba = namedtuple("Proba", ["hollande", "sarkozy"])
possibilities = [Proba(h, s) for (h, s) in product(numpy.linspace(0, 1, 101),
numpy.linspace(0, 1, 101))]