Skip to content

Instantly share code, notes, and snippets.

View pykong's full-sized avatar
🎯
Focusing

Ben Felder pykong

🎯
Focusing
View GitHub Profile
  1. First, create a table in your database into which you will import the CSV file. After the table is created:

  2. Log in to your database using SQL Server Management Studio.

  3. Right click the database and select Tasks -> Import Data... Click the Next > button.

  4. For Data Source, select Flat File Source. Then use the Browse button to select the CSV file. Spend some time configuring the data import before clicking the Next > button.

  5. For Destination, select the correct database provider (e.g. for SQL Server 2012, you can use SQL Server Native Client 11.0). Enter the Server name; check Use SQL Server Authentication, enter the User name, Password, and Database before clicking the Next > button.

  6. In the Select Source Tables and Views window, you can Edit Mappings before clicking the Next > button.

  7. Check Run immediately and click the Next > button.

  8. Click the Finish button to run the package.

class Borg:
_shared_state = {}
def __init__(self):
self.__dict__ = self._shared_state
git checkout .
from itertools import izip // you may also just use zip
l = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 0)]
result = [sum(x) for x in izip(*l)]
print(result)
>>> [25, 20]
@pykong
pykong / rm_dir.py
Last active November 21, 2017 21:41
Also works when dir does not exist, so there is no need for LBYL.
import shutil
shutil.rmtree(role_fs_path, ignore_errors=True)
@pykong
pykong / get_neighbours.py
Last active December 5, 2017 18:23
Gets both numbers adjacent to input number.
import bisect
def get_neighbours(num, interval):
interval = set(interval)
interval.discard(num)
interval = list(interval)
interval.sort()
if num < interval[0] or interval[-1] < num:
@pykong
pykong / get_active_view.py
Created November 18, 2017 19:41
Often used.
def get_active_view(self):
"""Return the active view in the currently active window."""
return sublime.active_window().active_view()
# Write this:
if (mark.a, mark.b) == (region.a, region.b):
...
# much cleaner than:
if mark.a == region.a and mark.b == region.b:
...
@pykong
pykong / build_nested_dict.py
Last active November 13, 2017 22:07
Use this logic instead of a sequence of key checks.
l0 = {}
l1 = l0.setdefault("key_l1", {})
l2 = l1.setdefault("key_l2", [])
l2.append("3")
{'key_l1': {'key_l2': ['3']}}