Skip to content

Instantly share code, notes, and snippets.

package main
import (
"errors"
"fmt"
"io"
"log"
"net"
"strings"
"time"
@rongyi
rongyi / main.go
Created November 10, 2017 08:25 — forked from mschoebel/main.go
Snippet: login/logout (Golang)
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"net/http"
)
// cookie handling
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''For running command line executables with a timeout'''
import subprocess
import threading
import shlex
import sys
import traceback
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import shlex
import subprocess
import select
@rongyi
rongyi / stardict2txt.py
Last active May 3, 2023 12:15
convert a stardict dictionary to txt
#!/usr/bin/python
# -*- coding: utf-8 -*-
import struct
import types
import gzip
class IfoFileException(Exception):
"""Exception while parsing the .ifo file.
Now version error in .ifo file is the only case raising this exception.
package main
import (
"log"
"time"
)
const (
// MaxWorker : max work count
MaxWorker = 100
@rongyi
rongyi / gist:32796d775240cb7cc58e7c6e3e56f59d
Created September 2, 2016 07:51 — forked from nschum/gist:2626303
better "enum class" indent in Emacs
;; This hack fixes indentation for C++11's "enum class" in Emacs.
;; http://stackoverflow.com/questions/6497374/emacs-cc-mode-indentation-problem-with-c0x-enum-class/6550361#6550361
(defun inside-class-enum-p (pos)
"Checks if POS is within the braces of a C++ \"enum class\"."
(ignore-errors
(save-excursion
(goto-char pos)
(up-list -1)
(backward-sexp 1)
@rongyi
rongyi / nodejs-repl-eval.el
Created August 26, 2016 04:41 — forked from emallson/nodejs-repl-eval.el
Evaluation functions for the `nodejs-repl' Emacs package.
;;; nodejs-repl-eval.el --- Summary
;;; Commentary:
;;;
;;; Evaluation functions for the `nodejs-repl' package. Written on a stormy
;;; night between days of node hacking.
;;;
;;; Code:
(require 'js2-mode)
(require 'nodejs-repl)
@rongyi
rongyi / bottom_gnome_termial_tab
Created May 17, 2015 05:27
show gnome-terminal tab at bottom
// add the code below to terminal_window_init function at line about 2034
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (priv->notebook), GTK_POS_BOTTOM);
@rongyi
rongyi / gist:3fbbd112e7798039cd8c
Created March 20, 2015 08:49
two ways to get cpu cores
#include <thread>
#include <iostream>
#include <unistd.h>
using std::cout;
using std::endl;
int main()
{
cout << std::thread::hardware_concurrency() << endl;
cout << sysconf(_SC_NPROCESSORS_ONLN) << endl;