Skip to content

Instantly share code, notes, and snippets.

Felix Descoteaux felix-d

View GitHub Profile
@felix-d
felix-d / review.rb
Created Apr 27, 2020
Review git branches
View review.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
require 'ostruct'
require 'net/http'
require 'json'
require 'pathname'
options = OpenStruct.new(
@felix-d
felix-d / lru.rs
Created Oct 21, 2018
LRU Cache in Rust
View lru.rs
#![feature(box_syntax)]
#![feature(box_into_raw_non_null)]
#![feature(nll)]
use std::collections::HashMap;
use std::hash::Hash;
use std::ptr::NonNull;
use std::cell::RefCell;
#[derive(Debug)]
@felix-d
felix-d / sieve.rs
Created Apr 16, 2018
Sieve of Erathostene in Rust
View sieve.rs
extern crate num_iter;
use num_iter::range_step;
pub fn sieve(n: u64) -> Vec<u64> {
let mut prime_identifers: Vec<bool> = vec![true; n as usize + 1];
let primes: Vec<u64> = vec![];
for i in 2..(n as f64).sqrt() as usize + 1 {
if *prime_identifers.get(i).unwrap() {
View downloader.rs
let video_file_regex = Regex::new(r"https://.*\.ts").unwrap();
let mut result_video_file = File::create("result.ts")?;
let futures: Vec<_> = video_file_regex.find_iter(&hd_playlist_content).map(|capture| {
let video_file_link = capture.as_str();
let response = client.get(video_file_link.parse().unwrap());
response.unwrap().body().concat2()
}).collect();
View gist:c5defd471c99617343d6a01aef5b8b34
" vim: set sw=2 ft=vim ts=2 sts=2 et:
"""""""""""""""""""""""""""""""
" => BUNDLES
"""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
@felix-d
felix-d / Dockerfile
Last active Apr 8, 2019
Elixir Phoenix Distillery Multi-Stage Dockerfile
View Dockerfile
# Assets compilation
FROM aparedes/alpine-node-yarn as node
## Node modules
COPY ./deps /tmp/deps
COPY ./assets/package.json /tmp/deps
COPY ./assets/package-lock.json /tmp/deps
WORKDIR /tmp/deps
RUN yarn
View curlt.bash
#!/bin/bash
# shamelessly stolen from https://github.com/mat/dotfiles/blob/master/bin/curlt
#
# curl wrapper returning timing information.
#
# curl format adapted from
# http://josephscott.org/archives/2011/10/timing-details-with-curl/
#
# Example usage:
# $ curlt http://www.apple.com
@felix-d
felix-d / sqllogging.rb
Created Oct 23, 2017
SQL logging with trace
View sqllogging.rb
class MyLogger < Logger
def add(severity, message = nil, progname = nil)
severity ||= UNKNOWN
if @logdev.nil? or severity < @level
return true
end
if progname.nil?
progname = @progname
end
if message.nil?
@felix-d
felix-d / ffi_string.rs
Created Jul 9, 2017
FFI - Convert C strings to Rust strings
View ffi_string.rs
extern crate libc;
use std::ffi::CStr;
use libc::c_char;
pub extern fn to_owned(buf: *const c_char) -> String {
let c_str: &CStr = unsafe { CStr::from_ptr(buf) };
let buf: &[u8] = c_str.to_bytes();
let str_slice: &str = std::str::from_utf8(buf).unwrap();
str_slice.to_owned()
@felix-d
felix-d / Track Emacs position inside terminal
Created Jul 3, 2015
Track current position inside emacs term
View Track Emacs position inside terminal
if [ -n "$INSIDE_EMACS" ]; then
chpwd() { print -P "\033AnSiTc %d" }
print -P "\033AnSiTu %n"
print -P "\033AnSiTc %d"
fi
You can’t perform that action at this time.