Skip to content

Instantly share code, notes, and snippets.

@Ation
Ation / array_shuffle.cs
Created January 4, 2014 12:16
c#_array_shuffle
private static void ShuffleArray(IList<int> array)
{
if (array == null) throw new ArgumentNullException("array");
var r = new Random((int) DateTime.Now.Ticks);
for (int i = array.Count-1; i >= 0; --i)
{
var index = r.Next(i+1);
if (index == i) continue;
@Ation
Ation / Unordered_allocator
Created August 17, 2014 17:34
Custom allocator for unordered_set (use malloc-free) instead of new
template<class _Ty>
class MyAllocator
: public _Allocator_base<_Ty>
{ // generic MyAllocator for objects of class _Ty
public:
typedef MyAllocator<_Ty> other;
typedef _Allocator_base<_Ty> _Mybase;
typedef typename _Mybase::value_type value_type;
@Ation
Ation / chain.hpp
Last active August 29, 2015 14:06
Chain
#include <functional>
#include <deque>
#include <stdexcept>
template<class T = void*> class Chain {
public:
typedef Chain<T> my_type;
typedef std::function< T (my_type &) > callback;
typedef std::function< void (my_type &, std::exception &) > fail_callback;
@Ation
Ation / file_regex
Created December 8, 2014 11:34
Sublime C++ build system file_regex
"file_regex": "^(.*?):([0-9]+):?([0-9]+)?:? error:(.*)$"
@Ation
Ation / is_module_installed.py
Created April 22, 2015 20:51
Check if python module installed
import subprocess
def is_python_module_installed(module):
command = ['pip', 'list']
p = PO( command, stdin=PIPE, stdout = PIPE, stderr = PIPE)
output,err = p.communicate
for module in output.decode('utf-8').splitlines():
if module.split(' ')[0] == module:
return True
@Ation
Ation / google_proxy.js
Created July 21, 2015 17:29
Google compression proxy
/**
* Data Compression Proxy Extension for Google Chrome on Desktop
* (c) 2014 Jerzy Głowacki. License: Apache 2.0
*/
var MD5 = function(e) {
 function h(a,b){var c,d,e,f,g;e=a&2147483648;f=b&2147483648;c=a&1073741824;d=b&1073741824;g=(a&1073741823)+(b&1073741823);return c&d?g^2147483648^e^f:c|d?g&1073741824?g^3221225472^e^f:g^1073741824^e^f:g^e^f}function k(a,b,c,d,e,f,g){a=h(a,h(h(b&c|~b&d,e),g));return h(a<<f|a>>>32-f,b)}function l(a,b,c,d,e,f,g){a=h(a,h(h(b&d|c&~d,e),g));return h(a<<f|a>>>32-f,b)}function m(a,b,d,c,e,f,g){a=h(a,h(h(b^d^c,e),g));return h(a<<f|a>>>32-f,b)}function n(a,b,d,c,e,f,g){a=h(a,h(h(d^(b|~c),e),g));return h(a<<f|a>>>32-f,b)}function p(a){var b="",d="",c;for(c=0;3>=c;c++)d=a>>>8*c&255,d="0"+d.toString(16),b+=d.substr(d.length-2,2);return b}var f=[],q,r,s,t,a,b,c,d;e=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",d=0;d<a.length;d++){var c=a.charCodeAt(d);128>c?b+=String.fromCharCode(c):(127<c&&2048>c?b+=String.fromCharCode(c>>6|192):(b+=String.fromCharCode(c>>12|224),b+=Stri
@echo off
rmdir /Q /S build
echo "Build removed"
pushd stub-cpp\src\main\python
git co develop
git pull
python build_env.py debug
#{ "keys": [ "ctrl+alt+v" ], "command": "open_in_browser" },
import sublime, sublime_plugin
import webbrowser
import os.path
import sys
class OpenInBrowserCommand(sublime_plugin.TextCommand):
def run(self, edit):
filePath = self.view.file_name()
fileToOpen = os.path.basename(filePath)
import os
import shutil
import subprocess
def generate_project():
command = ['python', 'generate_project.py', 'release']
result = subprocess.call(command)
if result == 0:
print 'Project generated'
return True
@Ation
Ation / gist:dede01da9e8f705049dbfb34ee9e71de
Created October 17, 2018 09:24
install ccache ubuntu
# Install package
sudo apt install -y ccache
# Update symlinks
sudo /usr/sbin/update-ccache-symlinks
# Prepend ccache into the PATH
echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc
# Source bashrc to test the new PATH