Skip to content

Instantly share code, notes, and snippets.

View samueltardieu's full-sized avatar

Samuel Tardieu samueltardieu

View GitHub Profile
use tokio::time::Duration;
async fn value<T>(x: T, duration: Duration) -> T {
println!("Before sleeping in value");
tokio::time::sleep(duration).await;
println!("After sleeping in value");
x
}
async fn identity<T>(x: &mut T) -> &mut T {
fn identity<T>(x: &mut T) -> &mut T {
println!("In identity");
x
}
fn main() {
let mut x = 0i32;
println!("Before assignment");
*identity(&mut x) = { println!("Evaluating 42"); 42 };
println!("After assignment");
@samueltardieu
samueltardieu / gist:7946839
Created December 13, 2013 16:24
Freebox Companion pour Android
D/FbxCompMain( 7542): launching activity for 'Téléchargements'
I/ActivityManager(  850): START u0 {cmp=fr.freebox.android.compagnon/.downloadmanager.FbxDownloadListActivity (has extras)} from pid 7542
D/FbxDownloadListActivity( 7542): called onCreate
D/FbxDownloadListActivity( 7542): tab selected
D/FbxDownloadListFragment( 7542): called onCreate
D/FbxDownloadListActivity( 7542): called onStart
D/FbxDownloadListActivity( 7542): called onResume
D/FbxHttpClientTask( 7542): got 403, application/json; charset=utf-8 on http://88.160.xxx.yyy:81/api/v1/connection/config
D/FbxHttpClientTask( 7542): called doInBackground on: http://88.160.xxx.yyy:81/api/v1/fs/ls//?countSubFolder=1&removeHidden=1
@samueltardieu
samueltardieu / Factor.hs
Created June 23, 2013 08:13
Demo Factor basis for the non-classical paradigms and language course
module Factor where
import Control.Monad.State
-- We can put integer literals or quotations on the stack
data Stackable = IntLiteral Int
| FQuotation (Factor ())
-- Shortcut name
type Stack = [Stackable]
@samueltardieu
samueltardieu / Test.scala
Created June 17, 2013 15:38
Scala seems to always prefer value over call by name: `foo(true)` returns "foo1" and is not ambiguous. Why?
object Test {
def foo(t: Boolean) = "foo1"
def foo(t: => Boolean) = "foo2"
}
@samueltardieu
samueltardieu / LockMap.java
Last active December 16, 2015 09:49
Add comments, and create already locked semaphores in order to reduce further contention opportunities.
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
public class LockMap<Key> {
private final ConcurrentHashMap<Key, Semaphore> map = new ConcurrentHashMap<Key, Semaphore>();
public void lock(final Key key) throws InterruptedException {
Semaphore sem = map.get(key);
while (true) {
shortenUrl :: String -> String
shortenUrl url = case splitFileName url of
(dir, "index.html") | isLocal dir -> dir
_ -> url
where isLocal uri = isPrefixOf rootUrl uri || not (isInfixOf "://" uri)
@samueltardieu
samueltardieu / challenge.c
Created March 11, 2013 12:58
Le communication challenge fait en cours ce matin. Et il fonctionne :)
#include "ch.h"
#include "hal.h"
#include "lcd.h"
#define SCORED_QUIZZ 1
#define TEST_QUIZZ 2
// Define this as TEST_QUIZZ or SCORED_QUIZZ
#define QUIZZ TEST_QUIZZ
@samueltardieu
samueltardieu / gist:4512923
Created January 11, 2013 18:38
scala> ((x: Int, y: Int) => x+y).getClass.getMethods.find(_.getName == "apply").get.getParameterTypes.size res49: Int = 2
scala> ((x: Int, y: Int) => x+y).getClass.getMethods.find(_.getName == "apply").get.getParameterTypes.size
res0: Int = 2
// Le getMethods.find(_.getName == "apply") est dû au fait qu'il y a deux apply possible,
// un avec des "int", et un avec des "Object" (à cause de la possibilité de passer des
// "Integer") -- vive l'interaction avec la JVM. Mais ces deux apply auront obligatoirement
// la même arité.
@samueltardieu
samueltardieu / gist:4120844
Created November 20, 2012 20:28
lsusb -v
Bus 002 Device 073: ID 08e6:5501 Gemplus GemProx-PU Contactless Smart Card Reader
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64