Skip to content

Instantly share code, notes, and snippets.

@singalen
singalen / _example.rs
Last active November 4, 2021 00:22
Newbie lifetime problem
use rlua::{Context, Error, FromLua, Lua, Value};
fn eval2<'lua, T>(lua_text: &str) -> rlua::Result<T> // line 190
where T: FromLua<'lua>
{
let lua = Lua::new();
let result = lua.context(|lua_ctx: Context<'lua>| {
let result = lua_ctx
function package_deps() {
BINARY=$1
DEPS=$(otool -L $BINARY \
| grep "/opt/local/lib" \
| tr -s ' ' \
| cut -d ' ' -f 1)
for DEP in $DEPS; do
cp $DEP Far2l.app/Contents/MacOS/
@singalen
singalen / preprocessor.cpp
Last active December 24, 2019 21:06
Wesnoth crash on iPad
preprocessor_data::preprocessor_data(preprocessor_streambuf& t,
filesystem::scoped_istream i,
const std::string& history,
const std::string& name,
int linenum,
const std::string& directory,
const std::string& domain,
std::unique_ptr<std::map<std::string, std::string>> defines,
bool is_define)
: preprocessor(t)
@singalen
singalen / far2l.lldb.bt3
Last active September 20, 2018 19:53
far2l freeze on vim
(lldb) process interrupt
Process 21193 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00007fff5bacc20a libsystem_kernel.dylib`mach_msg_trap + 10
libsystem_kernel.dylib`mach_msg_trap:
-> 0x7fff5bacc20a <+10>: retq
0x7fff5bacc20b <+11>: nop
libsystem_kernel.dylib`mach_msg_overwrite_trap:
0x7fff5bacc20c <+0>: movq %rcx, %r10
@singalen
singalen / (cause)parser.cpp
Last active March 25, 2018 08:17
wesnoth 1.10 iOS crash: stack-use-after-scope
void write_key_val_visitor::operator()(t_string const &value) const
{
bool first = true;
// Crashes:
for (t_string::walker w(value); !w.eos(); w.next())
// Doesn't crash:
for (t_string::walker w(value.get()); !w.eos(); w.next())
// ...
}
1. Windows: https://stackoverflow.com/questions/29438430/how-to-get-dpi-scale-for-all-screens
2. OS X: https://stackoverflow.com/questions/12589198/how-to-read-the-physical-screen-size-of-osx
3. GTK: https://stackoverflow.com/questions/25048987/in-gtk-linux-whats-the-correct-way-to-get-the-dpi-scale-factor
4. Qt: https://stackoverflow.com/questions/20603931/how-to-get-the-dpi-of-the-display-screen-in-qt
static ProfileCounter counter_one("profiled_function");
void profiled_function()
{
...
{
ProfileGuard g(&counter_one);
do_some_timed_activity();
}
...
@singalen
singalen / forest.c
Created November 11, 2016 22:13
A stepwise resource allocation in C. Example for http://softwareengineering.stackexchange.com/questions/335851/
int f() {
FILE *fp = NULL;
Forest* forest = NULL;
Tree *tree = NULL;
Element *element = NULL;
int status = 0;
fp = fopen("data.txt", "rb");
forest = generate_forest(fp, ...);
if (!forest) {
@singalen
singalen / with offending laptop
Created September 2, 2013 08:29
torba-wifi-slowdown
BSS 90:94:e4:ef:51:34 (on wlan0) -- associated
TSF: 235968921975 usec (2d, 17:32:48)
freq: 2412
beacon interval: 100
capability: ESS Privacy ShortSlotTime APSD (0x0c11)
signal: -65.00 dBm
last seen: 116 ms ago
Information elements from Probe Response frame:
SSID: Torba Lab
Supported rates: 1.0* 2.0* 5.5* 11.0* 9.0 18.0 36.0 54.0
@singalen
singalen / JettyLauncher.java
Created June 20, 2012 20:18
Jetty+Weld+Jersey-servlet setup for StackOverflow question
package com.foobar.chaos;
import javax.naming.InitialContext;
import javax.naming.Reference;
import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class JettyLauncher {