Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomasz Sterna smokku

View GitHub Profile
View gfx2d_circle.rs
const STEPS: usize = 16;
let pos = vec2(collider.x, collider.y);
let mut vertices = Vec::with_capacity(STEPS);
for step in 0..STEPS {
let m = Transform::FromOrigin {
pos,
scale: vec2(1.0, 1.0),
rot: ((2. * PI / STEPS as f32) * step as f32, Vec2::zero()),
}
.matrix();
View serialize.rs
let mut registry = TypeRegistryInternal::default();
registry.register::<f32>();
registry.register::<bool>();
registry.register::<Vec2>();
registry.register::<components::Position>();
registry.register::<components::KineticBody>();
...
for entity in entities.iter() {
if let Some(location) = world.get_entity_location(*entity) {
let archetype = &world.archetypes[location.archetype as usize];
View megaui.rs
use crate::{constants, GameGraphics};
use bevy::{
app::startup_stage,
input::{
keyboard::{KeyCode, KeyboardInput},
mouse::MouseButtonInput,
},
math::{vec2, Vec2},
prelude::*,
};
View 📊 Weekly development breakdown
Rust 7 hrs 53 mins ████████████████████▋ 98.3%
Text 4 mins ▏░░░░░░░░░░░░░░░░░░░░ 0.9%
TOML 2 mins ░░░░░░░░░░░░░░░░░░░░░ 0.5%
Other 1 min ░░░░░░░░░░░░░░░░░░░░░ 0.2%
Markdown 0 secs ░░░░░░░░░░░░░░░░░░░░░ 0.0%
@smokku
smokku / rwlock_futex.c
Last active Nov 1, 2019
Linux futex based Read-Write Lock implementation
View rwlock_futex.c
#define cpu_relax() __builtin_ia32_pause()
#define cmpxchg(P, O, N) __sync_val_compare_and_swap((P), (O), (N))
static unsigned _lock = 1; // read-write lock futex
const static unsigned _lock_open = 1;
const static unsigned _lock_wlocked = 0;
static void _unlock()
{
unsigned current, wanted;
View ffmpeg-vita.sh
for i in *.mkv; do nice ffmpeg -i "$i" -c:v libx264 -preset slow -crf 20 -tune animation -profile:v high -level 4.0 -vf scale=-1:540 -c:a aac -strict -2 -ac 2 -c:s mov_text -map_metadata 0 -y "${i/.mkv/.mp4}" </dev/null; done
@smokku
smokku / fish_prompt.fish
Created Apr 21, 2016
fish prompt with hostname emoji and git status
View fish_prompt.fish
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
# hostname emoji
for name in (hostname | tr . '\n')
@smokku
smokku / lib_init.c
Created Dec 28, 2015
ELF .init_array example
View lib_init.c
static void my_cool_main(int argc, char* argv[], char* envp[])
{
// your code goes here
}
__attribute__((section(".init_array"))) void (* p_my_cool_main)(int,char*[],char*[]) = &my_cool_main;
@smokku
smokku / webpack.config.js
Created Sep 28, 2015
node-proxy capitalize lower case headers
View webpack.config.js
var http = require('http');
var setHeader = http.OutgoingMessage.prototype.setHeader;
http.OutgoingMessage.prototype.setHeader = function() {
var match, submatch;
arguments[0] = arguments[0].replace(/\b(\w)/g, function(match, submatch) {
return submatch ? submatch.toUpperCase() : "";
});
setHeader.apply(this, arguments);
};