Skip to content

Instantly share code, notes, and snippets.

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

spike SpikeXy

🏠
Working from home
View GitHub Profile
@SpikeXy
SpikeXy / Generator.Demo.py
Last active October 2, 2017 01:52
Generator #python
# 我们创建了一个generator后,基本上永远不会调用next(),而是通过for循环来迭代它,并且不需要关心StopIteration的错误
>>> g = (x * x for x in range(10))
>>> for n in g:
... print(n)
...
0
1
4
9
>>> import os # 导入os模块,模块的概念后面讲到
>>> [d for d in os.listdir('.')] # os.listdir可以列出文件和目录
['.emacs.d', '.ssh', '.Trash', 'Adlm', 'Applications', 'Desktop', 'Documents', 'Downloads', 'Library', 'Movies', 'Music', 'Pictures', 'Public', 'VirtualBox VMs', 'Workspace', 'XCode']
@SpikeXy
SpikeXy / Range.Demo.cs
Last active October 2, 2017 01:53
range #python
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@SpikeXy
SpikeXy / enumerate.Demo.cs
Last active October 2, 2017 01:53
enumerate #python
# Python内置的enumerate函数可以把一个list变成索引-元素对,这样就可以在for循环中同时迭代索引和元素本身:
>>> for i, value in enumerate(['A', 'B', 'C']):
... print(i, value)
...
0 A
1 B
2 C
@SpikeXy
SpikeXy / isIterable.Demo.py
Last active October 2, 2017 01:53
isIterable #python
# 判断对象是否是可以迭代的对象
>>> from collections import Iterable
>>> isinstance('abc', Iterable) # str是否可迭代
True
>>> isinstance([1,2,3], Iterable) # list是否可迭代
True
>>> isinstance(123, Iterable) # 整数是否可迭代
False
@SpikeXy
SpikeXy / getActions.cs
Last active October 2, 2017 01:54
getActionsInController #csharp
// 获取controller中的所有action和description
Assembly asm = Assembly.GetAssembly(typeof(NjModelmgr.MvcApplication));
var controlleractionlist = asm.GetTypes()
.Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type))
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
.Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
.Select(x => new
{
Controller = x.DeclaringType.Name,
@SpikeXy
SpikeXy / SPFieldMultiChoiceValue.AddOrdUpdate.Demo.cs
Last active October 2, 2017 01:55
SPFieldMultiChoiceValue #sharepoint
//新增或者更新SPListItem中的多选字段
SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue();
foreach (JObject item7 in item3)
{
var itemChoiceName = item7.GetValue("key").ToString();
//var itemChoiceValue = item7.GetValue("value").ToString();
values.Add(itemChoiceName);
}
spListItem[itemName] = values;
@SpikeXy
SpikeXy / JObject.JArray.Demo.cs
Last active October 2, 2017 01:55
JObject JArray #csharp
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
@SpikeXy
SpikeXy / SetCustomProperty.Replace.Function.Demo.cs
Last active October 2, 2017 01:56
SetCustomProperty.Replace #sharepoint
using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ConsoleApplication2
{
class Program
@SpikeXy
SpikeXy / CreateMap.Demo.cs
Last active October 2, 2017 01:56
CreateMap Mapper #csharp
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp10
{
class Program