Skip to content

Instantly share code, notes, and snippets.

@Olwaro
Olwaro / README.md
Created June 30, 2015 09:24
HNX Theme for zsh

HNX Theme

This is my personnal theme. It is a modification of the agnoster theme.

Difference with agnoster

  • Two lines prompt
  • Support for python virtual environements
  • No "error" icon when last command returned a non-zero value
  • New color scheme, sections goes from darker to brighter (from left to right)
@Olwaro
Olwaro / README.md
Last active August 29, 2015 14:04
Handy function to concatenate stuff into a new string.

##How it works## It leverages c++11 variadic templates to create a convenient shortcut to the classic :

std::ostringstream oss;
oss << "This" << " and something else";
oss.str(); // Use the return value for what you want

##How to use it## Simply call the concat function.

@Olwaro
Olwaro / gist:9254010
Created February 27, 2014 16:47
Humanize setup fails on windows
Traceback (most recent call last):
File "setup.py", line 18, in <module>
long_description=open('README.rst').read(),
File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2017: character maps to <undefined>
@Olwaro
Olwaro / MainWindow.xaml.cs
Created December 2, 2013 20:11
Fun with WPF4.5 and Rx
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
namespace waving_progressbars
{
public partial class MainWindow
{
@Olwaro
Olwaro / gist:6669846
Last active December 23, 2015 17:39
C# one-liner for a parallel approximation of Pi.
/// <summary>
/// C# one-liner for a parallel approximation of Pi.
/// </summary>
/// <param name="iter">Number of iteration (the bigger it is, the better the approxiamtion will be)</param>
/// <returns>Pi !</returns>
static double ParallelPi(int iter)
{
return Enumerable.Range(0, iter).AsParallel().Select(i => (4*Math.Pow(-1, i))/(2*i + 1)).Sum();
}
@Olwaro
Olwaro / gist:5956964
Last active December 19, 2015 12:48
Create xml file with .NET XDocument
XDocument xdoc =
new XDocument(
new XElement("format",
new XElement("separateur", separateur), // simple tag
new XElement("delimiteur", delimiteur),
new XElement("skip", skipEntete ? "1" : "0"),
new XElement("colones", // foreach items in list 'choix' : return a tag with some attributes
choix.Select(ci => new XElement("col", new XAttribute("ordre", choix.IndexOf(ci)), new XAttribute("champ", ci.Identifiant)))
)
)
@Olwaro
Olwaro / gist:5196473
Created March 19, 2013 14:19
VS snippet for RelayCommand
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>RelayCommand</Title>
<Author></Author>
<Description></Description>
<HelpUrl></HelpUrl>
<SnippetTypes />
<Keywords />
@Olwaro
Olwaro / Extensions.cs
Last active December 14, 2015 09:09
C# extension method that emulate SQL's IN (...).
public static class Extensions
{
public static bool In<T>(this T obj, params T[] others) where T : IEquatable<T>
{
bool res = false;
for (int i = 0; i < others.Length; i++)
{
if (obj.Equals(others[i]))
{
@Olwaro
Olwaro / th.html
Created July 22, 2012 18:26
Capture img from 4chan thread code
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>???</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Le styles -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
@Olwaro
Olwaro / main.cpp
Created July 21, 2012 22:23
Fun with C++11 smart ptr
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
class Stuff
{
int val;
public: