This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn arrange(&self, ui: &mut Ui, state: &mut DashboardState, repulsion_steps: usize, compaction_steps: usize) { | |
if state.block_rect.is_empty() { | |
return; | |
} | |
let original = state.block_rect.clone(); | |
let mut debug_copy = state.block_rect.clone(); | |
let rects = &mut state.block_rect; | |
let keys: Vec<BlockKey> = rects.keys().collect(); | |
let keys = keys.iter().copied(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this in your `update` to render marks under the cursor to tell if your input is slow | |
let input_pos = ui.ctx().input(|input| input.pointer.latest_pos()); | |
let marks = ui.memory_mut(|mem| { | |
let marks: &mut VecDeque<Pos2> = | |
mem.data.get_temp_mut_or_default(Id::new("dots")); | |
if let Some(pos) = input_pos { | |
if pos == marks.back().cloned().unwrap_or_default() { | |
// Add a small offset if position is repeated | |
marks.push_back(pos + vec2(3.0, 3.0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn render_switch(&self, ui: &mut Ui, id: Id, labels: &[&str; 2], selected: usize, available: Rect) -> Response { | |
let text_color = ui.visuals().strong_text_color(); | |
let galley1 = ui.fonts(|fonts| fonts.layout_no_wrap(labels[0].to_owned(), FontId::monospace(9.0), text_color)); | |
let galley2 = ui.fonts(|fonts| fonts.layout_no_wrap(labels[1].to_owned(), FontId::monospace(9.0), text_color)); | |
let margin = vec2(10.0, 4.0); | |
// Initial estimation of the position. It will be moved below | |
let rect = Rect::from_min_size(Pos2::ZERO, | |
vec2( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[extension_trait] | |
pub impl UiExt for Ui { | |
fn inner_shadow_top(&mut self, mut avail_rect: Rect, opacity: f32) { | |
let painter = self.painter(); | |
avail_rect.set_height(1.0); | |
const STEPS: usize = 8; | |
for i in 0..STEPS { | |
let alpha = 1.0 - (i as f32 / STEPS as f32); | |
let shift = avail_rect.height() * i as f32; | |
let rect = avail_rect.translate((0.0, shift).into()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Helper function to center arbitrary widgets. It works by measuring the width of the widgets after rendering, and | |
// then using that offset on the next frame. | |
fn centerer(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) { | |
ui.horizontal(|ui| { | |
let id = ui.id().with("_centerer"); | |
let last_width: Option<f32> = ui.memory_mut(|mem| mem.data.get_temp(id)); | |
if let Some(last_width) = last_width { | |
ui.add_space((ui.available_width() - last_width) / 2.0); | |
} | |
let res = ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Any command invoked with the pind prefix gets stored along with its $PWD so | |
# subsequent invocations are executed in the same directory. For example: | |
# | |
# $ pind pwd | |
# /home/juan | |
# $ cd /etc | |
# $ pind pwd | |
# /home/juan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stashit () | |
{ | |
for i in `seq 0 20`; | |
do | |
echo Changed files:; | |
git stash show stash@{$i}; | |
echo Untracked files:; | |
git diff --summary stash@{$i}^2; | |
echo; | |
while true; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 443 ssl http2; | |
error_log stderr warn; | |
ssl_certificate /etc/certs/nginx-selfsigned.crt; | |
ssl_certificate_key /etc/certs/nginx-selfsigned.key; | |
server_name localhost; | |
location / { | |
access_by_lua_block { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RUNS=5 | |
for i in `seq 1 $RUNS`; do | |
starttime=`date "+%s%3N"` | |
# Generate a significant amount of output | |
ls -Rl /usr/ /usr/ /usr/ /usr/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fullAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
const restrictedAlphabet = 'BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz'; | |
const threadPrefix = 'thread-'; | |
const messagePrefix = 'msg-'; | |
const isWhitespace = str => /^[\s\xa0]*$/.test(str); | |
const isInvalidString = str => str ? (str.indexOf(threadPrefix) !== -1 || str.indexOf(messagePrefix) !== -1) : false; | |
const encode = function(str) { | |
if (isWhitespace(str)) return str; |
NewerOlder