Skip to content

Instantly share code, notes, and snippets.

@blaswan
blaswan / UserInputText
Created August 25, 2013 07:55
사용자로부터 문자열 입력받는 기본 예제 * InputStream - byte * InputStreamReader - character * BufferedReader - 문자열
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException {
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader b = new BufferedReader(r);
String userInput = b.readLine();
System.out.println("user input :"+userInput);
@blaswan
blaswan / centered_mixin.less
Last active December 25, 2015 18:18
가운데 정렬하기 위한 less Mixin
.wrapped {
position: relative;
width: 100%;
height: 100%;
}
.centered (@width, @height) {
position: absolute;
top: 50%;
left: 50%;
@blaswan
blaswan / mixin_top_to_bottom_gradient.less
Created October 17, 2013 03:54
Top to bottom gradient Mixin in less
.top-to-bottom-gradient (@top-color, @bottom-color) {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(@top-color), to(@bottom-color)); /* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(top, @top-color, @bottom-color); /* Safari 5.1, Chrome 10+ */
background: -moz-linear-gradient(top, @top-color, @bottom-color); /* Firefox 3.6+ */
background: -ms-linear-gradient(top, @top-color, @bottom-color); /* IE 10 */
background: -o-linear-gradient(top, @top-color, @bottom-color); /* Opera 11.10+ */
}
@blaswan
blaswan / random_token.js
Last active December 25, 2015 18:18
The function that creates 256 bits random string token
function randomToken(length) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz0123456789+/'
, string = ''
, randomNumber
, i;
length = length ? length : 32;
for (i = 0; i < length; i++) {
randomNumber = Math.floor(Math.random() * chars.length);
// Copyright (C) 2013 Polychrom Pty Ltd
//
// This program is licensed under the 3-clause "Modified" BSD license,
// see LICENSE file for full definition.
package com.polychrom.examples;
import java.util.concurrent.ExecutorService;
import android.app.Activity;
@blaswan
blaswan / .jshintrc
Created February 3, 2014 10:17 — forked from haschek/.jshintrc
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
@blaswan
blaswan / server.js
Created February 11, 2014 15:28 — forked from ageldama/server.js
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
@blaswan
blaswan / getBlurredBitmap.java
Created February 24, 2014 11:23
getBlurredBitmap
public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) {
if (VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius); //0.0f ~ 25.0f
public static Bitmap getCircularCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap scaledBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
scaledBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
} else {
scaledBitmap = bitmap;
}
Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(), Bitmap.Config.ARGB_8888);
public static Bitmap getScaledBitmapFromUri(Context context, Uri uri) {
InputStream inputStream;
try {
inputStream = context.getContentResolver().openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, options);
inputStream.close();
int width = options.outWidth;