Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
codeswimmer / ios_IPAddress.c
Created January 15, 2012 16:49
iOS: Get Current IP Address
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
@codeswimmer
codeswimmer / Android: Tiled Background
Created July 5, 2011 11:40
Android: How to display a tiled bitmap background
// ============================================================================================
// Code
//
// Example showing how to set a View's background to a tiled bitmap.
// assumes: res/drawable/pattern01.png - The bitmap representing an individual tile
public void setViewTiledBackground(View view, Resources resources) {
Bitmap tile = BitmapFactory.decodeResource(resources, R.drawable.pattern02);
BitmapDrawable tiledBitmapDrawable = new BitmapDrawable(resources, tile);
tiledBitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
@codeswimmer
codeswimmer / Android Horizontal Scrollable GridView
Created March 14, 2011 19:16
Android: GridView that scrolls horizontally and vertically
public class Test extends Activity {
GridView gv;
Gallery g[] = new Gallery[3];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gv = (GridView)findViewById(R.id.gridview);
gv.setAdapter(new GAdapter());
for (int i = 0; i < g.length; i++) {
@codeswimmer
codeswimmer / Android.Bitmap.Rotate
Created March 7, 2011 17:25
Android: rotate a bitmap
public Bitmap rotateBitmap(Bitmap original, float degrees) {
int width = original.getWidth();
int height = original.getHeight();
Matrix matrix = new Matrix();
matrix.preRotate(degrees);
Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true);
Canvas canvas = new Canvas(rotatedBitmap);
canvas.drawBitmap(original, 5.0f, 0.0f, null);
@codeswimmer
codeswimmer / Android: assets folder access
Created April 10, 2011 01:19
Android: How to use access files stored in the assets folder
/* How to use access files stored in the assets folder:
*
* Files saved in the assets/ directory are not given a resource ID, so you can't reference them through the R class or from XML resources.
* Instead, you can query files in the assets/ directory like a normal file system and read raw data using AssetManager.
*
* However, if all you require is the ability to read raw data (such as a video or audio file), then save the file in the res/raw/ directory
* and read a stream of bytes using openRawResource().
*
* Notes:
* * AssetManager.list(String path)
@codeswimmer
codeswimmer / Android: Programmatically Launch Home Screensd
Created May 5, 2011 16:37
Android: Programmatically Launch Home Screen
// Remove the Activity parameter if this is being placed into a class that derives from Activity
public void launchHomeScreen(Activity activity) {
Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
activity.startActivity(homeIntent);
}
@codeswimmer
codeswimmer / git_reset2head_recursive
Created November 18, 2011 19:11
git: recursively reset a git submodule hierarchy to HEAD
git submodule foreach git submodule init && git submodule update --recursive
@codeswimmer
codeswimmer / chaocipher.perl
Created December 17, 2011 22:12
perl: Chaocipher
# ChaoSim.pl : Simulation of Chaocipher enciphering/deciphering
# (c) Moshe Rubin, August 2010
# email: mosher@mountainvistasoft.com
use strict;
use diagnostics;
use warnings;
my $left = uc($ARGV[1]);
my $right = uc($ARGV[2]);
my $mode = $ARGV[3];
@codeswimmer
codeswimmer / Android.Set.Orientation
Created March 10, 2011 01:19
Android: programmatically set screen orientation
Use this to make it landscape:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
...and this to make it portrait:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@codeswimmer
codeswimmer / ios_simple_pasteboard.m
Created January 2, 2013 20:10
iOS: Simple Usage Of UIPasteBoard
Basically, UIPasteBoard allows us to share data to other application. Below is an example of UIpasteBoard usage.
COPY
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
appPasteBoard.persistent = YES;
[appPasteBoard setString:@"STRING TO COPY"];
PASTE