2017-11-01 linux sed replace 图灵1234567891011sed -i 's/\\"//g' filesed -i 's/\\\\\//\//g' filesed -i 's/"\[{""json"":""/\[/g' filesed -i 's/{""json"":""//g' filesed -i 's/"",""mt"":[0-9]*}\]"/\]/g' filesed -i 's/"",""mt"":[0-9]*}//g' file Use double quotes so that sed would expand variables.sed "s|\$ROOT|${HOME}|" abc.sh shell变量在双引号内会被解析 在单引号内不会被解析 How to use variables in a command in sed?
2017-10-25 redis redis-delete-all-keys Flushall 1redis 127.0.0.1:6379> FLUSHALL Redis Flushall 命令Redis常用命令集,清空redis缓存数据库
2017-10-25 django django transform queryset to dict model_to_dict方法12from django.forms.models import model_to_dictmodel_to_dict(instance) 参考链接 toDict方法123456789101112131415class Category(models.Model): autoid = models.AutoField(primary_key=True) email=models.CharField(max_length=150,blank=False) comtype=models.CharField(max_length=20,blank=False) catname=models.CharField(max_length=150,blank=False) def __unicode__(self): return '%s' % (self.catname) def toJSON(self): import json return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]])) def toDict(self): return dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]) 可读性更强的版本 12345678910111213141516171819202122def toJSON(self): fields = [] for field in self._meta.fields: fields.append(field.name) d = {} for attr in fields: d[attr] = getattr(self, attr) import json return json.dumps(d) def toDict(self): fields = [] for field in self._meta.fields: fields.append(field.name) d = {} for attr in fields: d[attr] = getattr(self, attr) return d 参考链接
2017-10-25 redis django redis cache delete pattern Example use of delete_pattern 12>>> from django.core.cache import cache>>> cache.delete_pattern("foo_*") Simple search keys by pattern 123>>> from django.core.cache import cache>>> cache.keys("foo_*")["foo_1", "foo_2"] django-redis