Skip to content

Instantly share code, notes, and snippets.

View samueltardieu's full-sized avatar

Samuel Tardieu samueltardieu

View GitHub Profile
@samueltardieu
samueltardieu / pell.py
Created November 26, 2010 22:47
Solve the Pell equation
"""Compute solutions to the diophantine Pell equation x^2-D*y^2=1."""
import itertools
def pell (D):
"""Return the smallest integer set solving Pell equation
x^2-D*y^2=1 where x, D and y are positive integers. If there are no
solution (D is a square), return None.
>>> pell(3)
USING: hash-sets kernel locals math sequences sets ;
IN: acm
:: add ( set n -- newset )
HS{ } clone :> newset
set members [ n [ + ] [ - ] 2bi [ newset adjoin ] bi@ ] each newset ;
:: least ( n -- x )
HS{ 0 } 1 [ [ add n over in? ] keep swap ] [ 1 + ] until nip ;
int netaccept(int fd, char *server, int *port)
{
int cfd = 0;
int one = 0;
union {
struct sockaddr_in ipv4;
struct sockaddr_in6 ipv6;
} sa;
socklen_t len = sizeof sa;
int rc = 0, af;
@samueltardieu
samueltardieu / ips.c
Created July 26, 2011 09:54 — forked from bortzmeyer/gist:1086392
Resolve names, using the standard library (so, going through NSS and things like that, unlike dig)
// Compile with -std=gnu99 to get the proper definitions of struct addrinfo
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
@samueltardieu
samueltardieu / test.scala
Created July 29, 2011 20:17
Type erasure and reification
class Example {
println("Constructing an Example object: " + this)
}
object Test extends App {
// Return a new object of type T when called as f[T]
def f[T : Manifest] = manifest[T].erasure.getConstructor().newInstance()
@samueltardieu
samueltardieu / AndroidUtils.scala
Created October 11, 2011 09:46
Current (working but not polished) implementation of onUI and onBG
import scala.collection.mutable.{HashMap, Map}
import scala.concurrent.Channel
import scala.concurrent.ops.spawn
import android.content.Context
import android.os.{Handler, Message}
object AndroidBG {
private val androidBGs: Map[Context, AndroidBG] = new HashMap()
@samueltardieu
samueltardieu / CachesMapDownloader.java
Created October 25, 2011 07:19
Downloader thread
package cgeo.geocaching.maps;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgSearch;
import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.lang3.StringUtils;
import android.os.Handler;
import akka.actor._
import akka.event.Logging
object Bug extends App {
ActorSystem("Bug").actorOf(Props[Bug])
}
class Bug extends Actor with FSM[Int, (Int, Int)] {
@samueltardieu
samueltardieu / gist:1808253
Created February 12, 2012 12:24
Free Mobile Android mobileconfig log
V/NetworkChangeReceiver( 2372): Network Change
D/FREEMOBILE( 1848): ----------------------------------- UTILS -------------------------
D/FREEMOBILE( 1848): : true
D/FREEMOBILE( 1848): R :1
D/FREEMOBILE( 1848): ### Receiver : android.net.conn.CONNECTIVITY_CHANGE
W/System.err( 1848): android.provider.Settings$SettingNotFoundException: button_mvno_roaming_key
W/System.err( 1848): at android.provider.Settings$System.getInt(Settings.java:908)
W/System.err( 1848): at fr.freemobile.android.mobileconfig.RoamingListener.checkRoamingStatus(RoamingListener.java:142)
W/System.err( 1848): at fr.freemobile.android.mobileconfig.RoamingListener.onReceive(RoamingListener.java:90)
@samueltardieu
samueltardieu / PKGBUILD
Created April 10, 2012 11:20
Working PKGBUILD for saleae-logic
# Contributor: Kyle Keen <keenerd@gmail.com>
pkgname=saleae-logic
pkgver=1.1.15
pkgrel=3
pkgdesc="High speed USB logic analyzer."
arch=(i686 x86_64)
url="http://www.saleae.com/"
license=('unknown') # closed source, none given
depends=('gcc-libs' 'gtk2' 'libice')
makedepends=()