Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
c0ldlimit / gist:4389093
Last active December 10, 2015 05:38
Python: Simple One-Line IF Statement #python #c0ldlimit
# value_when_true if condition else value_when_false
'Yes' if fruit == 'Apple' else 'No'
@c0ldlimit
c0ldlimit / gist:4391824
Last active December 10, 2015 05:58
Pandas: Widen output display #pandas #c0ldlimit #python
#� http://stackoverflow.com/questions/11707586/python-pandas-widen-output-display
from pandas.util.terminal import get_terminal_size
get_terminal_size()
from pandas import set_printoptions
set_printoptions(max_rows=200,max_columns=10)
@c0ldlimit
c0ldlimit / gist:4431530
Last active December 10, 2015 11:59
#python using logging module
# http://docs.python.org/release/2.3.5/lib/node304.html
# http://www.blog.pythonlibrary.org/2012/08/02/python-101-an-intro-to-logging/
import logging
logger = logging.getLogger('myapp')
hdlr = logging.FileHandler('/var/tmp/myapp.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.WARNING)
@c0ldlimit
c0ldlimit / gist:4459497
Created January 5, 2013 03:11
#python #dict Using setdefault and from collections import #defaultdict
newdata = {}
for k, v in DATA_SOURCE:
newdata.setdefault(k, []).append(v)
print newdata
from collections import defaultdict
newdata = defaultdict(list)
DATA_SOURCE = (('key1', 'value1'),
@c0ldlimit
c0ldlimit / gist:4513717
Created January 11, 2013 20:29
#SQL IF EXIST UPDATE ELSE INSERT for SQL Server 2005 because it doesn't have the merge operation
UPDATE dbo.customer_comments
SET customer_comment= @comment + 'something here'
WHERE customer_id = @customerId
IF @@ROWCOUNT = 0
INSERT INTO dbo.customer_comments (customer_id, customer_comment)
VALUES (@customerId, @comment)
@c0ldlimit
c0ldlimit / gist:4541732
Created January 15, 2013 20:25
#windows Run a Windows scheduled task remotely
schtasks /end /s <machine name> /tn <task name> /U <Username> /P <Password>
schtasks /?
# http://technet.microsoft.com/en-us/library/cc766266.aspx
# http://stackoverflow.com/questions/290559/how-do-i-stop-start-a-scheduled-task-on-a-remote-computer-programatically
@c0ldlimit
c0ldlimit / gist:4961066
Last active July 27, 2023 16:52
Setting up #Ubuntu #ubuntu
sudo apt update
sudo apt upgrade
# https://www.digitalocean.com/community/tutorials/how-to-create-a-new-sudo-enabled-user-on-ubuntu-22-04-quickstart
# https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-linux/
# https://docs.conda.io/en/main/miniconda.html
# Setting up Ubuntu
# check locale
@c0ldlimit
c0ldlimit / gist:5028006
Created February 25, 2013 05:46
#sqlite3 #python returning datetime from sqlite in Python
# http://stackoverflow.com/questions/1829872/read-datetime-back-from-sqlite-as-a-datetime-in-python
db = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES)
c = db.cursor()
c.execute('create table foo (bar integer, baz timestamp)')
c.execute('insert into foo values(?, ?)', (23, datetime.datetime.now()))
c.execute('select * from foo')
c.fetchall()
[(23, datetime.datetime(2009, 12, 1, 19, 31, 1, 40113))]
@c0ldlimit
c0ldlimit / gist:5028008
Last active December 14, 2015 04:28
#sqlite3 #python Parameterized queries
# http://zetcode.com/db/sqlitepythontutorial/
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys
uId = 1
uPrice = 62300
@c0ldlimit
c0ldlimit / gist:5028010
Created February 25, 2013 05:47
#sqlite3 #python Dictionary cursor
# http://zetcode.com/db/sqlitepythontutorial/
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys
con = lite.connect('test.db')