Skip to content

Instantly share code, notes, and snippets.

@tell-k
tell-k / gist:c7552ef551f06620e2f029f1495fe173
Last active April 14, 2018 05:03
ブロック内のコードをスキップできる + スコープを共有しない with statetment
# 1. ブロック内のコードを実行しない with -------
# refs http://stackoverflow.com/questions/12594148/skipping-execution-of-with-block
import sys
import inspect
class SkipContext:
def __enter__(self):
# 1. SkipContextの外側のframeを取得
self.frame, _, _, _, _, _ = inspect.getouterframes(inspect.currentframe())[1]
@tell-k
tell-k / 0_reuse_code.js
Created February 11, 2014 10:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
class Point
attr_accessor :user
def initialize(user)
@user = user
end
def calc_point_num
unless self.user.point_num
return 101
# -*- coding: utf-8 -*-
"""
Connpass API Wrapper
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Requirement
- Requests (http://docs.python-requests.org/en/latest/)
See Also
@tell-k
tell-k / fixed_element_with_remove_addressbar.html
Created February 14, 2013 05:30
mediaクエリーで、アドレスバーを消す前と、消した後で要素の位置(高さ)を固定にしたい時のサンプル
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
/*
初期表示が height: 546px
アドレスバーを消すと height: 615px になる場合
@tell-k
tell-k / paramiko_proxycommand_sample.py
Last active April 14, 2021 10:07
paramikoのProxyCommandのサンプル
#!/usr/bin/env python
#-*- coding:utf8 -*-
# paramiko の ProxyCommandの Sample
# -------------------------------------------------
#
# ~/.ssh/config
#
# Host proxy-server
# User hoge
# AND OR とかも直感的に使える
from sqlalchemy.sql.expression import *
# AND
Entry.query.filter(and_(Entry.id == 1, Entry.text == "entry")).all()
# => SELECT * FROM entries WHERE entries.id = 1 AND entries.text = "entry"
# OR
Entry.query.filter(or_(Entry.id == 1, Entry.text == "entry")).all()
# => SELECT * FROM entries WHERE entries.id = 1 OR entries.text = "entry"
INSERT INTO entries (id, text, created_at) VALUES (%s, %s, %s)
(1, 'entrytext1', datetime.datetime(2012, 9, 15, 0, 39, 7, 668106))
SELECT entries.id AS entries_id, entries.text AS entries_text, entries.created_at AS entries_created_at
FROM entries
WHERE entries.id = %s
LIMIT %s
(1, 1)
UPDATE entries SET text=%s WHERE entries.id = %s
db_session.add(Entry(id=1, text="entrytext1"))
entry1 = Entry.query.filter_by(id=1).first()
# プロパティを変更
entry1.text = "hogehoge"
db_session.flush()
# 結果取得を呼ばなければ単なるQueryオブジェクト
query = Entry.query.filter(Entry.id == 1) # => <class 'sqlalchemy.orm.query.Query'>
# クエリの付け加えもできる
if hoge == True:
query = query.filter(Entry.text == "entry")
# hoge = True : SELECT * FROM entries WHERE entries.id = %s AND entries.text = %s
# hoge = False : SELECT * FROM entries WHERE entries.id = %s