Skip to content

Instantly share code, notes, and snippets.

View shengoo's full-sized avatar

shengoo

  • Beijing, China
View GitHub Profile
@shengoo
shengoo / runsp.cs
Created June 10, 2014 01:58
run sp with ef
private DataSet GetDataSetBySp(string inName, SqlParameter[] inParams)
{
using (var IPPDB = new IPPEntities())
{
using (var spCmd = new SqlCommand())
{
DataSet ds = null;
IPPDB.Database.Connection.Open();
spCmd.Connection = (SqlConnection)(IPPDB.Database.Connection);
@shengoo
shengoo / download.cs
Created May 28, 2014 02:58
c# download file
public bool download(HttpContextBase httpContext, int id)
{
long speed = 1024*1024;
bool ret = true;
try
{
#region--验证:HttpMethod,请求的文件是否存在
switch (httpContext.Request.HttpMethod.ToUpper())
{ //目前只支持GET和HEAD方法
case "GET":
@shengoo
shengoo / umbraco bind event.md
Last active August 29, 2015 14:01
Application startup events & event registration

#Application startup events & event registration In order to bind to certain events in the Umbraco application you need to make these registrations during application startup. Based on the Umbraco version you are using there are various ways to hook in to the application starting. The higher the version you are using the more robust this becomes.

In all of the samples below, they show you how to setup an object to execute during Umbraco application startup so that you can subscribe to the Document.BeforePublish event.

#Using ApplicationEventHandler to register events ###Applies to: Umbraco 6.1.0+

The ApplicationEventHandler is a new robust way to hook in to the Umbraco application startup process. It is a base class so all you need to do is override the methods that you wish to handle. It is important to know the difference between each of the methods (information is below). Most of the time you will just want to execute code on the ApplicationStarted method.

@shengoo
shengoo / append datatable
Last active August 29, 2015 14:01
Merge datatable
private static void DemonstrateMergeTable()
{
DataTable table1 = new DataTable("Items");
// Add columns
DataColumn idColumn = new DataColumn("id", typeof(System.Int32));
DataColumn itemColumn = new DataColumn("item", typeof(System.Int32));
table1.Columns.Add(idColumn);
table1.Columns.Add(itemColumn);
@shengoo
shengoo / Selected columns from DataTable
Created May 8, 2014 07:54
Selected columns from DataTable
var view = new DataView(datatable);
var myRows = view.ToTable(false, "id").Select();
var idlist = myRows.Select(x => x["id"]).ToList();
@shengoo
shengoo / use $compile outside a directive in Angularjs
Created May 6, 2014 09:45
use $compile outside a directive in Angularjs
$(function() {
// myApp for test directive to work, ng for $compile
var $injector = angular.injector(['ng', 'myApp']);
$injector.invoke(function($rootScope, $compile) {
$('body').prepend($compile('<div ng-attr-tooltip="test">Cancel</div>')($rootScope));
});
});
@shengoo
shengoo / VisualStudio.gitignore
Created May 6, 2014 02:47
VisualStudio.gitignore
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
@shengoo
shengoo / JavaScript module pattern
Created April 24, 2014 07:47
JavaScript module pattern
//自执行函数(immediately invoked function)
(function(){
}());
//这样也可以(this works too)
(function(){})();
//增加参数(add params to first)
(function(my){
@shengoo
shengoo / null and undefined in javascript
Last active August 29, 2015 14:00
null and undefined in javascript
> var un;
> console.log(un);
undefined
> var nu = null;
> console.log(nu);
null
> typeof un
'undefined'
> typeof nu
'object'
@shengoo
shengoo / Android unzip file using ZipInputStream
Last active February 27, 2017 08:33
Android unzip file using ZipInputStream
public class unzip extends Activity {
/** Called when the activity is first created. */
static final int BUFFER = 2048;
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
textView = new TextView(this);