Skip to content

Instantly share code, notes, and snippets.

View felix-d's full-sized avatar

Felix Descoteaux felix-d

View GitHub Profile

0x1f8972432b6e8ac7125be0bbfbddc22a7a35f8f3bcdff01407c36a15c986ab51

@felix-d
felix-d / review.rb
Created April 27, 2020 13:12
Review git branches
#!/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 October 21, 2018 18:36
LRU Cache in Rust
#![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 April 16, 2018 01:44
Sieve of Erathostene in Rust
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() {
@felix-d
felix-d / downloader.rs
Created April 2, 2018 22:46
Downloader
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();
" 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 April 8, 2019 15:51
Elixir Phoenix Distillery Multi-Stage 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
#!/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 October 23, 2017 17:47
SQL logging with trace
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 July 9, 2017 17:43
FFI - Convert C strings to Rust strings
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()