Skip to content

Instantly share code, notes, and snippets.

View gongzhitaao's full-sized avatar
🐢
(๑•̀ㅂ•́)و✧

Zhitao Gong gongzhitaao

🐢
(๑•̀ㅂ•́)و✧
  • DeepMind
  • Montreal, CA
  • 12:12 (UTC -04:00)
View GitHub Profile
@gongzhitaao
gongzhitaao / README.md
Last active January 4, 2025 03:38
Analog Clock

Simple analog clock.

var svg = document.querySelector( "svg" );
var svgData = new XMLSerializer().serializeToString( svg );
var canvas = document.createElement( "canvas" );
var ctx = canvas.getContext( "2d" );
var img = document.createElement( "img" );
img.setAttribute( "src", "data:image/svg+xml;base64," + btoa( svgData ) );
img.onload = function() {
@gongzhitaao
gongzhitaao / README.md
Last active August 29, 2015 14:00
I'm a demo

This is a demo gist to test my gist viewer. The Javascript may not be written by me :D

This is a test for update.

@gongzhitaao
gongzhitaao / hs.conf.el
Last active November 30, 2022 07:59
hideshow config for emacs
(defface collapsed-face '((t (:background "#e0cf9f" :foreground "#5f5f5f"))) "Collapsed Overlay")
(defvar collapsed-face 'collapsed-face)
(define-fringe-bitmap 'hs-marker [0 24 24 126 126 24 24 0])
(defun display-code-line-counts (ov)
(when (eq 'code (overlay-get ov 'hs))
(let* ((marker-string "*fringe-dummy*")
(marker-length (length marker-string))
(display-string
(format " (%d)... "
@gongzhitaao
gongzhitaao / sed-one-liner
Created October 23, 2013 02:43
sed one-liner
# input:
# 1 1
# 2 2
# 3 3
# 4 4
# 5 5
# 6 6
# 7 7
# output:
# 1
@gongzhitaao
gongzhitaao / CppTimer.md
Last active January 28, 2024 14:25
Simple high resolution timer in C++

A simple Timer class that provides satisfying resolution.

API

  • Timer() constructs the timer.
  • .reset() resets the timer
  • .elapsed() returns elapsed seconds in double since last reset.
@gongzhitaao
gongzhitaao / clsfunccnt
Last active December 25, 2015 13:19
1. Count lines of code (LOC),, excluding blank lines and comments 2. Count number of methods in a class
#!/bin/bash
# usage: ./clsfunccnt <directory> <filename-regex> <classname>
find $1 -regex "$2" -exec cat {} \; | \
sed -n "
# find target class
/^class\s\+$3:/,/^class.*/{
# print all def's with 4 spaces indent
/\s\{4\}def\s\+.*/p
@gongzhitaao
gongzhitaao / convolution-parallel-mpi.cpp
Last active December 25, 2015 09:59
Simple sequential and parallel implementation of convolution in C++
#include <fstream>
#include <mpi.h>
inline double convolute(double **img, const double (*w)[11],
int r, int c)
{
double s = 0;
for (int i = 0; i < 11; ++i)
for (int j = 0; j < 11; ++j)
s += img[r-5+i][c-5+j] * w[i][j];
@gongzhitaao
gongzhitaao / CMakeLists.txt
Created October 7, 2013 04:23
A Minimum Working Example Using CMake to build project with Qt5 forms
# suppose you have created a ui file called configwin.ui
cmake_minimum_required (VERSION 2.6)
project(tst)
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
<script type="text/javascript">// <![CDATA[
function callTheJsonp()
{
// the url of the script where we send the asynchronous call
var url = "http://localhost/utils/jsonp/ajax.php?callback=parseRequest";
// create a new script element
var script = document.createElement('script');
// set the src attribute to that url
script.setAttribute('src', url);
// insert the script in out page