Skip to content

Instantly share code, notes, and snippets.

@summivox
summivox / cmaes_parallelize.m
Last active March 18, 2016 13:02
Prepare a Simulink model for repeated parameterized simulation in Rapid Accelerator mode.
function f_para = cmaes_parallelize(f_orig)
f_para = @f;
function scores = f(vs)
n = size(vs, 2);
scores = zeros(1, n);
parfor i = 1:n
scores(i) = f_orig(vs(:, i));
end
end
end
@summivox
summivox / reload_workspace.m
Last active December 5, 2015 16:36
Simulink: reload model workspace init script
function reload_workspace
% Call this function in `Init`, `PostLoadFcn`, and/or `PreSaveFcn` model
% callbacks to ensure that model workspace init script is auto-reloaded.
ws = get_param(bdroot, 'ModelWorkspace');
ws.reload;
@summivox
summivox / slrt_conf_init.m
Last active November 5, 2015 17:27
Simulink Realtime: common conf + solver override
function slrt_conf_init(conf, solver, Ts)
% initialize configuration of current model with default, then override
% with given solver and timestep setting
%
% conf: path to common configuration file
% solver: 'FixedStepDiscrete', 'ode8', 'ode4', ...
% Ts: fixed step time of solver
%
% NOTE: SLRT allows only fixed-step solvers
@summivox
summivox / renren-adblock-201511.user.js
Last active November 5, 2015 14:50
block some renren ads and fix some layout bugs (now hosted on greasyfork.org)
// ==UserScript==
// @name renren-adblock-201511
// @namespace https://github.com/summivox
// @version 0.1
// @description block some renren ads and fix some layout bugs
// @author summivox
// @match *://*.renren.com/*
// @grant none
// ==/UserScript==
@summivox
summivox / caps-ime.ahk
Last active October 30, 2015 04:00
Remap CapsLock to LWin+Space for switching IME (Windows 8+)
CapsLock::#Space
+CapsLock::+#Space
@summivox
summivox / read_plot_write.m
Last active October 30, 2015 14:06
MatLab trick: read-plot-write an image
img = imread('in.png');
f = figure('visible', 'off');
imshow(img, 'Border', 'tight');
hold on;
rectangle('Position', [100, 200, 300, 150], 'EdgeColor', 'y');
hold off;
F = getframe(gcf);
imwrite(F.cdata, 'out.png');
close(f);
@summivox
summivox / read_file.m
Created October 21, 2015 02:14
Simulink Realtime tricks -- read target PC file/scope
function raw = read_file(filename)
% reads back one SLRT file
f = SimulinkRealTime.fileSystem;
h = fopen(f, filename);
raw = fread(f, h);
f.fclose(h);
end
@summivox
summivox / init.m
Created October 21, 2015 02:11
Simulink Realtime tricks -- init script for setting up paths
currentFolder = fileparts(mfilename('fullpath'));
cd(currentFolder);
addpath(genpath([currentFolder '/src']));
addpath(genpath([currentFolder '/include']));
set_param(0, 'CacheFolder', [currentFolder '/build']);
set_param(0, 'CodeGenFolder', [currentFolder '/build']);
@summivox
summivox / pdisk2.m
Created September 20, 2015 01:38
2D Poisson Disk Sampling
function [result, r] = pdisk2(sizes, n, maxAttempt)
% Generate $n$ evenly spread-out 2d points in given region using Poisson
% disk method
%
% sizes: [xMax, yMax]
% actual range: 0 <= x < xMax, 0 <= y < yMax
% n: # of points
% maxAttempt: # of candidates generated per iteration (optional)
xMax = sizes(1);
@summivox
summivox / no-auto-reboot.cmd
Last active August 29, 2015 14:25
stop windows from screwing you by forcing you to restart
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoRebootWithLoggedOnUsers /t REG_DWORD /d 1 /f
:: source: http://answers.microsoft.com/en-us/windows/forum/windows_8-windows_update/disable-automatic-forced-restart-after-windows/8c66d21c-7423-4c2d-a2ef-f4d7685422b0?auth=1