Skip to content

Instantly share code, notes, and snippets.

View mikehibm's full-sized avatar
🏠
Working from home

Mike I mikehibm

🏠
Working from home
View GitHub Profile
@mikehibm
mikehibm / main.xml
Created June 21, 2012 23:18
Android: 押されるとカクッと画像の角度が変わるボタン (main.xml)
<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_stateful"
/>
@mikehibm
mikehibm / UpdateProducts1.cs
Created December 6, 2012 05:57
EFTransactionサンプルコード
private void UpdateProducts() {
using (var context = new MyEntities()) {
using (var cn = context.Database.Connection) {
cn.Open();
using (var tr = context.Database.Connection.BeginTransaction()) {
try {
//1. ADO.NETで独自のSQL文を実行。
var sql = "UPDATE [Products] SET [Price] = [Price] * 1.1 ";
var cmd = cn.CreateCommand();
cmd.Transaction = tr;
@mikehibm
mikehibm / UpdateProducts2.cs
Created December 6, 2012 06:14
EFTransactionサンプルコード
private void UpdateProducts() {
using (var context = new MyEntities()) {
using (var cn = context.Database.Connection) {
cn.Open();
using (var tr = context.Database.Connection.BeginTransaction()) {
try {
//1. ADO.NETで独自のSQL文を実行。
var sql = "UPDATE [Products] SET [Price] = [Price] * 1.1 ";
var cmd = cn.CreateCommand();
cmd.Transaction = tr;
@mikehibm
mikehibm / UpdateProducts3.cs
Created December 6, 2012 06:49
EFTransactionサンプルコード
private void UpdateProducts() {
//EFと同じ接続文字列を使って先にSqlConnectionを作成。
using (var sqlConnection = new SqlConnection(new MyEntities().Database.Connection.ConnectionString)) {
//作成済みのSqlConnectionを使ってDbContextを作成。
using (var context = new MyEntities(sqlConnection)) {
//EntityConnectionのOpenメソッドを呼ぶ。
IDbConnection entityConnection = ((IObjectContextAdapter)context).ObjectContext.Connection;
@mikehibm
mikehibm / PreventSubmitByEnterKey
Last active December 13, 2015 18:38
Prevent forms from being submitted by ENTER key in a text input field.
$(function(){
$("input[type=text]").keypress(function(e) {
var c = e.which ? e.which : e.keyCode;
return c != 13;
});
});
@mikehibm
mikehibm / PreventSubmitAndMoveFocusByEnterKey
Last active December 13, 2015 18:39
Prevent submiting form and move focus to next input field when Enter key is pressed.
$(function(){
var elements = "input[type=text]";
$(elements).keypress(function(e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13) {
var index = $(elements).index(this);
$(elements + ":gt(" + index + "):first").focus();
e.preventDefault();
}
});
@mikehibm
mikehibm / PreventSubmitAndMoveFocusWithEnterKey2
Last active December 13, 2015 18:48
Move focus with Enter key in a form. Move backward with Shift+Enter too.
$(function(){
var elements = "input[type=text]";
$(elements).keypress(function(e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13) {
var index = $(elements).index(this);
var criteria = e.shiftKey ? ":lt(" + index + "):last" : ":gt(" + index + "):first";
$(elements + criteria).focus();
e.preventDefault();
}
@mikehibm
mikehibm / AndroidAnimationViewRemove.java
Last active December 13, 2015 22:19
En example of removing a view after finishing an animation.
final ScaleAnimation scale = new ScaleAnimation(1.0f, 0.1f, 1.0f, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
final AlphaAnimation alpha = new AlphaAnimation(0.9f, 0.1f);
final AnimationSet set = new AnimationSet(true);
set.addAnimation(scale);
set.addAnimation(alpha);
set.setFillAfter(true);
set.setDuration(1500);
@mikehibm
mikehibm / AndroidAnimationRemoveViewError.java
Last active December 13, 2015 22:19
Example that produces an error on an animation end.
final ScaleAnimation scale = new ScaleAnimation(1.0f, 0.1f, 1.0f, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
final AlphaAnimation alpha = new AlphaAnimation(0.9f, 0.1f);
final AnimationSet set = new AnimationSet(true);
set.addAnimation(scale);
set.addAnimation(alpha);
set.setFillAfter(true);
set.setDuration(1500);
@mikehibm
mikehibm / CSVResult.cs
Last active December 31, 2015 16:59
ASP.NET MVCで任意のオブジェクトのIEnumerableを受け取ってCSVファイルを出力するクラス。
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Security;
using System.Text;
using System.Reflection;