Skip to content

Instantly share code, notes, and snippets.

@tsohr
tsohr / ClearActivity.java
Created May 30, 2013 03:31
Get the max limit texture size supported on the device dynamically. based on: http://android-developers.blogspot.kr/2009/04/introducing-glsurfaceview.html
package com.example.android.apis.graphics;
import java.nio.IntBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
@tsohr
tsohr / getRandomExternalImageContent.java
Last active September 17, 2021 04:41
Get an image resource from external content resolver randomly in Android.
protected static Uri getRandomExternalImageContent(Context c) {
ContentResolver resolver = c.getContentResolver();
if (resolver == null)
return null;
String [] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
int count = cursor.getCount();
int position = (int) (Math.random() * count);
@tsohr
tsohr / gist:5711945
Created June 5, 2013 06:15
Android activity manager "am" command help
adb shell am
usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
[--R COUNT] [-S] [--opengl-trace] <INTENT>
am startservice <INTENT>
am force-stop <PACKAGE>
am kill <PACKAGE>
am kill-all
am broadcast <INTENT>
am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]
@tsohr
tsohr / 1.screencap.sh
Last active July 7, 2017 07:03
Timestamp appended screen capture with ADB (android debug bridge) in Windows environment
#!/bin/bash
adb='/cygdrive/c/Android/sdk/platform-tools/adb.exe'
$adb shell screencap -p | perl -pe 's/\x0D\x0D\x0A/\x0A/g' > screen.png
STAMP=`date +"%Y%m%d_%H%M%S"`
mv -f screen.png screen-$STAMP.png
@tsohr
tsohr / gist:7942113
Last active September 6, 2017 06:35
7zip command line execution example, 7zip format, LZMA2, multithreading
# not working
#7za a -r -t7z -m=Deflate64 -mt=12 $FILE_OUT $A_DIR
7za a -r -t7z -m0=LZMA2 -mmt=on $FILE_OUT $A_DIR
#http://7zip.bugaco.com/7zip/MANUAL/switches/method.htm#ZipMultiThread
#mt=[off | on | {N}]
#Sets multithread mode. If you have a multiprocessor or multicore system, you can get a speed increase with this switch. This option #affects only compression with BZip2, Deflate and Deflate64 methods and decompression of BZip2 streams.
#Each thread in the multithread mode uses 32 MB of RAM for buffering. If you specify {N}, 7-Zip tries to use N threads.
Sub myline(x1, x2, l)
Dim i As Integer
Dim shp As Shape
Dim sld As Slide
Set sld = Application.ActiveWindow.View.Slide
Set shp = sld.Shapes.AddShape(37, x1, 10 * l, x2 - x1, 0)
shp.Fill.ForeColor.RGB = RGB(137, 143, 75)
shp.Fill.BackColor.RGB = RGB(137, 143, 75)
shp.ShapeStyle = 10002
@tsohr
tsohr / monitor
Last active August 29, 2015 14:05
#!/bin/sh
( tail -n 0 -f --follow=name --retry $* \
/var/log/audit/audit.log \
/var/log/messages \
/var/log/httpd/*log \
/var/log/tomcat/catalina.out \
/var/log/tomcat-rewrite.log \
/var/log/nginx/*log \
/var/log/firewalld \
/var/log/secure \
#!/bin/bash
/bin/socat TCP-LISTEN:23455,fork SYSTEM:"/root/monitor"
#!/bin/sh
( tail -n 0 -f --follow=name --retry $* \
/var/lib/containers/storage/overlay-containers/68dd6c9415c7988fff9eee72253caa8a0165b7d06e1854e81a3366db6daee271/userdata/ctr.log & \
journalctl --no-pager --follow --full & ) \
2>&1 \
| grep -v -i "audit.*res=success"
| grep -v -i "\(Completed 200 OK in\|Processing by Gitlab\)"
#
CREATE TABLE usertickets (
email varchar(128) NOT NULL default '',
ticket varchar(32) NOT NULL default '',
repositorygrants integer NOT NULL default '0'
);
CREATE TABLE usersgroups (
userid integer default '0',
groupid integer default '0'
);
CREATE TABLE users (