Skip to content

Instantly share code, notes, and snippets.

#Первый вариант использование ContentFile для непосредственной передачи контента в файл
from django.db import models
from django.core.files.base import ContentFile
class Instance(models.Model):
pdf = models.FileField(verbose_name=u'Файл в формате PDF')
instance = Instance()
name = u"somefilename"
instance.pdf.save(name, ContentFile("some pdf value")
-module(session).
-export([run/0]).
run() ->
{ok, C} = eredis:start_link(),
{ok, Session} = eredis:q(C, ["GET", "session:l7nruerw7i9tp3fr461q0lrbej72q5er"]),
String =erlang:binary_to_list(base64:decode(Session)),
Tokens = string:tokens(String,":"),
SessionValue = lists:nth(2,Tokens),
#!/bin/bash
Guest_name=exmaple.com
Host_ports=("7626" "8080" "8008")
Guest_ipaddr=192.168.0.1
Guest_ports=("22" "8001" "8008")
if [ "${1}" = "${Guest_name}" ]; then
if [ "${2}" = "start" ]; then
for ((i=0;i<${#Host_ports[@]};i++)); do
#http://stackoverflow.com/questions/14078065/how-set-erlang-node-name-when-run-an-erlang-application-by-basho-rebar-from-com
#http://www.erlang.org/doc/man/net_kernel.html
node(). #nonode@nohost
net_kernel:start([rumata, shortnames]).
node(). #'rumata@rumata-osx'
net_kernel:stop().
node(). #nonode@nohost
net_kernel:start(['rumata@myhost', longnames]).
node(). #rumata@myhost
#!/bin/bash
#usage change_owner.sh database_name new_owner_name
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $1` ; do
psql -c "alter table $tbl owner to $2" $1 ;
done
connection.openSignalingChannel = function(config) {
var websocket = new WebSocket('ws://localhost:8008/voice/my_group');
websocket.channel = config.channel || this.channel;
websocket.onopen = function () {
websocket.push(JSON.stringify({
open: true,
channel: websocket.channel
}));
if (config.callback) config.callback(websocket);
};
ffmpeg -f alsa -ac 1 -ab 128k -i pulse -f x11grab -r 25 -s 1280x1024 -i :0.0+0,0 -vcodec libx264 -vpre lossless_ultrafast -threads 0 video.mkv # record hq desktop
ffmpeg -i videokritbi.mp4 -sameq -acodec ac3 -ab 448k -ar 48000 output.avi # convert ti hq avi
import Control.Monad
import Data.Char
-- Code examples for
-- http://channel9.msdn.com/Series/C9-Lectures-Erik-Meijer-Functional-Programming-Fundamentals/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-8-of-13
newtype Parser a = P( String -> [(a, String)])
instance Monad Parser where
return v = P (\inp -> [(v,inp)])
def checkAccess(target, flag):
global user, groups
if user == "root":
return 1
try:
return {
'owner': lambda u: 1 if target['owner'] == u else 0,
'group': lambda u: 1 if targer['group'] == u else 0,
'r': lambda u: 0,
'w': lambda u: 1,
import pytest
from websocket import create_connection
@pytest.fixture(scope="module")
def ws(request):
ws = create_connection("ws://localhost:8080/bullet")
def fin():
ws.close()