Skip to content

Instantly share code, notes, and snippets.

View smokku's full-sized avatar

Tomasz Sterna smokku

View GitHub Profile
@smokku
smokku / webpack.config.js
Created September 28, 2015 10:17
node-proxy capitalize lower case headers
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);
};
@smokku
smokku / fish_prompt.fish
Created April 21, 2016 09:44
fish prompt with hostname emoji and git status
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')
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 / lib_init.c
Created December 28, 2015 17:04
ELF .init_array example
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;
use crate::{constants, GameGraphics};
use bevy::{
app::startup_stage,
input::{
keyboard::{KeyCode, KeyboardInput},
mouse::MouseButtonInput,
},
math::{vec2, Vec2},
prelude::*,
};
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];
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();
--- models/generate.orig.js 2022-02-16 16:38:08.286386783 +0100
+++ models/generate.js 2022-02-16 16:38:08.285386773 +0100
@@ -343,11 +343,11 @@
function handleField(field) {
let r = ''
if (field.description) r += ` /** ${sanitizeComment(field.description)} */\n`
- r += ` ${field.name}: ${handleFieldType(field.name, field.type)},`
+ r += ` ${field.name}: ${handleFieldType(field.name, field.type, field.args)},`
return r
}
TypeScript 4 hrs 41 mins ████████████▏░░░░░░░░ 57.8%
JavaScript 1 hr 26 mins ███▋░░░░░░░░░░░░░░░░░ 17.7%
HTML 38 mins █▋░░░░░░░░░░░░░░░░░░░ 7.9%
Other 30 mins █▎░░░░░░░░░░░░░░░░░░░ 6.2%
CSS 26 mins █▏░░░░░░░░░░░░░░░░░░░ 5.5%
@smokku
smokku / rwlock_futex.c
Last active December 16, 2023 23:45
Linux futex based Read-Write Lock implementation
#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;