Skip to content

Instantly share code, notes, and snippets.

View woxtu's full-sized avatar

woxtu

View GitHub Profile
@woxtu
woxtu / gist:c186b173be3a53171533
Last active March 4, 2019 05:37
Face detection in Rust
pub mod cv {
extern crate libc;
use self::libc::{c_char, c_double, c_int, c_schar, c_void};
#[repr(C)]
pub struct HaarClassifierCascade;
#[repr(C)]
pub struct MemStorage;
@woxtu
woxtu / bsconfig.json
Last active April 3, 2017 17:42
Conway's Game of Life in Facebook/Reason
{
"name": "lifegame",
"sources": [
"./"
]
}
@woxtu
woxtu / gist:7156835
Last active February 10, 2016 22:17
Draw a triangle using GLSL and VBO in Rouge
;; Rouge 0.0.15
(require "glut")
(require "opengl")
(def vertex-shader "
attribute vec3 position;
attribute vec4 color;
varying vec4 vertex_color;
@woxtu
woxtu / gist:7543972
Created November 19, 2013 11:24
Read the whole file into std::string in C++.
#include <fstream>
#include <string>
#include <iostream>
int main() {
std::ifstream stream{"fujiyama.txt"};
std::string buffer{std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>()};
std::cout << buffer << std::endl;
@woxtu
woxtu / gist:7237411
Created October 30, 2013 18:18
Do something when the animation of the navigation bar is complete
// in the view controller
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
UINavigationController* navigationController = (UINavigationController *)[window rootViewController];
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^{
[navigationController setNavigationBarHidden:YES animated:NO];
@woxtu
woxtu / gist:7045816
Created October 18, 2013 18:19
Convert image to Data URI in Rouge.
;; Rouge 0.0.14
(require "base64")
(require "mime/types")
(let [filename (nth ARGV 0)]
(let [data-type (-> filename MIME.Types/of first)
data-str (-> filename Kernel/open .read Base64/encode64)]
(.write (Kernel/open (str (File/basename filename) ".html") "wb")
(str "<!DOCTYPE html>\n" "<img src=\"data:" data-type ";base64," data-str "\" />"))))
@woxtu
woxtu / gist:6963724
Created October 13, 2013 15:46
Tweet in Rouge.
;; Rouge 0.0.14
(require "oauth")
(def *consumer-key* "YOUR CONSUMER KEY")
(def *consumer-secret* "YOUR CONSUMER SECRET")
(let [consumer-token (OAuth.Consumer. *consumer-key* *consumer-secret*
{:site "https://api.twitter.com/"})
request-token (.get_request_token consumer-token)]
import math
import os
import sequtils
import strutils
const libmecab = "libmecab.2.dylib"
type mecab_node_t = object
prev: ptr mecab_node_t
next: ptr mecab_node_t
(ns markov
(:require [cljs.nodejs :as nodejs]
[clojure.string :refer [join replace]]))
(def kuromoji (nodejs/require "kuromoji"))
(defn wakachi [tokenizer sentence]
(->> (js->clj (.tokenize tokenizer sentence) :keywordize-keys true)
(map :surface_form)))
extern crate time;
fn main() {
let now = time::now();
let year = now.tm_year as uint + 1900;
let month = now.tm_mon as uint + 1;
let first_wday = {
let mut t = now.clone();
t.tm_mday = 1;