Skip to content

Instantly share code, notes, and snippets.

@wvdschel
wvdschel / if_cascade.c
Created June 20, 2013 11:59
If-cascade I saw on HN. A, B and C can be bulky expressions, such as method calls or several conditions grouped together with ||. The second example has a number of advantages: (A) It offers a clearer split between conditions, so you don't have to squint your eyes and match parentheses. (B) It allows you to debug with much more ease: if somethin…
if( A && B && C )
{
...
}
//=========================//
if( A )
if( B )
if( C )
@wvdschel
wvdschel / ImageWallpaper.java
Created January 21, 2013 12:56
Crashes on line 31, EGL_BAD_ALLOC
private boolean initGL(SurfaceHolder surfaceHolder) {
mEgl = (EGL10) EGLContext.getEGL();
mEglDisplay = mEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (mEglDisplay == EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed " +
GLUtils.getEGLErrorString(mEgl.eglGetError()));
}
int[] version = new int[2];
#!/bin/bash
ADB_DEVICE_COUNT=`adb devices | wc -l`
ADB_DEVICE_COUNT=`expr $ADB_DEVICE_COUNT - 2`
if [ $ADB_DEVICE_COUNT -gt 0 ]
then
echo rebooting into fastboot
adb reboot bootloader
fi
@wvdschel
wvdschel / gist:3901511
Created October 16, 2012 19:43
PS1 etc
export PATH=~/Apps/bin:~/bin:$PATH:
export PS1='$(if [[ $? == 0 ]]; then echo -e "\[\033[0;32m\]\xE2\x9C\x94"; else echo -e "\[\033[0;31m\]\xE2\x9C\x95"; fi )\[\033[0m\] $(date +%R) \[\033[1;34m\]$(date +"%g%V.%u")\[\033[0;31m\] \w\[\033[0m\]\$ '"\033]0;$WINDOWTITLE\007"
@wvdschel
wvdschel / gist:3038553
Created July 3, 2012 08:43
Dump memory from gdb
unsigned int ReadWord(unsigned int *address)
{
return *address;
}
int DumpMemory(char *fileName, void* address, size_t size)
{
int file;
int ret = 0;
@wvdschel
wvdschel / flush.sh
Created June 21, 2012 14:44
Cache flush implementations
root@PLF-CPU:~# ./cacheflush_mips
Cached memory writes: 90000 ticks
Uncached memory writes: 300000 ticks
Userspace flush: block=1, 1100000 ticks, 0.00% errors
Userspace flush: block=2, 530000 ticks, 0.00% errors
Userspace flush: block=4, 450000 ticks, 0.00% errors
Userspace flush: block=8, 380000 ticks, 0.00% errors
Userspace flush: block=16, 340000 ticks, 0.00% errors
Userspace flush: block=32, 310000 ticks, 0.00% errors
Userspace flush: block=64, 310000 ticks, 0.00% errors
@wvdschel
wvdschel / gist:2901919
Created June 9, 2012 17:43
Drawing some land
package ;
import nme.display.Bitmap;
import nme.display.BitmapData;
import nme.display.Sprite;
import nme.display.StageAlign;
import nme.display.StageScaleMode;
import nme.display.Graphics;
import nme.events.Event;
import nme.Assets;
@wvdschel
wvdschel / mkswapimg.sh
Created June 4, 2012 07:45
Swap image creator
#!/bin/bash
SIZE=`expr $1 \* 1024`
if [[ x$SIZE == x ]]
then
MEM=`free | grep Mem | sed -e "s/[^0-9]*\([0-9]\+\).*/\1/"`
SIZE=`expr $MEM + $MEM / 4`
echo "No size provided, using 125% of memory size (${SIZE}KB)"
fi
COUNT=`expr $SIZE / 4`
@wvdschel
wvdschel / gist:2627572
Created May 7, 2012 12:47
Cats parser
# Stats about a single log
class Log
# Load a file and parse every line as a print.
def self.parse(file_path)
Log.new(file_path, File.readlines(file_path))
end
# Number of lines in the file and number of lines that are valid CATS prints
attr_reader :linecount, :cats_linecount,
# Number of characters that are in the file, part of CATS prints and part of CATS header overhead, respectively
@wvdschel
wvdschel / gist:2595804
Created May 4, 2012 16:09
CATS parsing magic
Dir['*.log'].each do |fname|
log = Log.parse(fname)
symbol = log.symbols.values.sort_by { |s| -s.charcount }.first
line = log.lines.values.sort_by { |s| -s.charcount }.first
puts "#{log.cats_charcount}/#{log.charcount} in #{log.name}, most offensive: #{symbol.name} (#{symbol.charcount}), #{line.name} (#{line.charcount})"
end
# Output:
# 2169/21484 in regexp-info.log, most offensive: -/legacy/printf (983), -/legacy/printf:0000 (983)
# 212132/227923 in teraterm.log, most offensive: amApp/resmgmt (22885), amApp/resmgmt:0850 (16423)