Skip to content

Instantly share code, notes, and snippets.

View QQism's full-sized avatar

QQ QQism

View GitHub Profile
@QQism
QQism / serializer_benchmarks.rb
Last active January 6, 2020 01:01 — forked from aishfenton/serializer_benchmarks.rb
Performance comparison of different ruby serializer methods
# gem install bson
# gem install bson_ext
# gem install yajl-ruby
# gem install json
# gem install msgpack
# gem install oj
require 'rubygems'
require 'benchmark'
require 'yaml'
@QQism
QQism / hello_opencl.c
Created March 25, 2018 08:12
A Minimal OpenCL Example
#include <stdio.h>
#include <sys/stat.h>
#include <OpenCL/OpenCL.h>
#define ARRAY_SIZE 1024
cl_context CreateContext()
{
cl_int errNum = 0;
cl_uint numPlatforms = 0;
@QQism
QQism / sieve-of-eratosthenes.clj
Created December 21, 2017 04:25
Sieve of Eratosthenes
(defn mark [xs idx]
"Iterate over the xs with each j step of (idx * idx + (j * idx))
For each element of step, mark them false (a.k.a not a prime number)"
(loop [arr xs
j 0]
(let [step (+ (* idx idx ) (* j idx))]
(if (< step (count arr))
(recur (assoc arr step false) (inc j))
arr))))

Keybase proof

I hereby claim:

  • I am quangquach on github.
  • I am quangquach (https://keybase.io/quangquach) on keybase.
  • I have a public key whose fingerprint is B1A4 BED0 393A 3556 38D0 15EC 2A7C 169F 75D5 E5A2

To claim this, I am signing this object:

This will format python datetime as a string to be used within jinja conditionals for comparing current date to article date using pelican app.
1. Create a file named jinjaext.py
2. paste the following snippet
def convertdate(datetime, format='%a-%d-%m-%Y'):
return datetime.date().strftime(format)
3. Add the following line to your config file
@QQism
QQism / convert_wav_to_mp3
Last active December 16, 2015 07:48
Convert all wav files in a path to mp3, using lame. Usage: ./convert_wav_to_mp3 my/wav/folder
#!/usr/bin/env python
# require lame http://lame.sourceforge.net
import sys
import os
import re
import subprocess
path = sys.argv[1:][0]
@QQism
QQism / vietjetair.html
Created September 10, 2012 00:05
vietjet air flights crawler
<!DOCTYPE html>
<html>
<head>
<title>Vietjet Air Crawlee</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<script>
window.onload = function() {
@QQism
QQism / tpl-rails3-db-charmer.md
Created August 8, 2012 07:51
TPL Rails 3.2 multiple database db-charmer QuickStart

Rails 3.2 multiple databases with DB-Charmer, Quickstart

Currently, to support rails 3.1 til 3.2.3, we need to install latest version (1.7.1)

gem 'db-charmer', '>= 1.7.1', :require => 'db_charmer'

Assume that we have two database server at 192.168.1.14 and 192.168.1.15

@QQism
QQism / postinstall
Created August 1, 2012 16:17
dotCloud postinstall to overwrite database.yml for rails app
#!/usr/bin/env ruby
require 'yaml'
DB_ADAPTER = "postgresql"
DATABASE = "my_database"
ENCODING = 'utf8'
TEMPLATE = 'template0'
TIMEOUT = 5000
POOL = 5