Skip to content

Instantly share code, notes, and snippets.

@lrhache
lrhache / export-mssql-csv.ps1
Last active March 11, 2024 20:06
Export all tables from a database to CSV files - AWS MSSQL 2008 / Win 2008
set-alias installutil $env:windir\microsoft.net\framework\v2.0.50727\installutil
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSProvider.dll"
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSSnapins.dll"
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
$SERVER_NAME="<SERVER NAME>"; $DB_NAME="<DB NAME>";$Tables = invoke-sqlcmd -query "SELECT name FROM sys.tables order by name" -database $DB_NAME -serverinstance $SERVER_NAME;foreach ($Table in $Tables){$TableName = $Table["name"];write-host -ForegroundColor Green "Creating File $TableName.csv";invoke-sqlcmd -query "SELECT * FROM $TableName" -database $DB_NAME -serverinstance $SERVER_NAME |export-csv -path D:\dump\$TableName.csv;}
@lrhache
lrhache / python-selenium-open-tab.md
Last active June 10, 2023 13:49
Python Selenium - Open new tab / focus tab / close tab

On a recent project, I ran into an issue with Python Selenium webdriver. There's no easy way to open a new tab, grab whatever you need and return to original window opener.

Here's a couple people who ran into the same complication:

So, after many minutes (read about an hour) of searching, I decided to do find a quick solution to this problem.

@lrhache
lrhache / heroku-set-configs-from-file.md
Created December 11, 2013 15:21
Easy way to batch set Heroku config from a file. No one wants to do this manually(!?).

#Heroku set configs from files

  • Export your configs from Heroku in "shell" format to file:

    $ heroku config -a <app_name> -s > .env-<environment_name(production, staging, ...)>
    
  • Copy this script to a file

@lrhache
lrhache / bitweekdays.py
Created January 8, 2016 15:37
Convert weekdays as bit representation
weekdays = ('Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Sunday', )
def convert_choice(*args):
"""Convert weekdays representation to 127 bits
Example:
>> # Monday, Tuesday, Friday, Sunday
>> bw.convert(1, 1, 0, 0, 1, 0, 1)
@lrhache
lrhache / list_unique_benchmark.py
Last active September 30, 2021 12:26
Two method to remove duplicates from a python list while keeping order
"""Benchmark multiple method of removing duplicates in a list
while keeping item's order in the list.
numpy.unique will likely be faster and more efficient
the more the list grows.
If a list is submitted to numpy.unique, it will be transformed and flattened
into a numpy.Array which it's data structure is more efficient than standard
lists since all elements have the same size in memory therefor requires less
access to the memory. Lists are stored as array of adresses pointing to
to the objects and requires more memory access (but more flexible).
@lrhache
lrhache / models.py
Last active June 14, 2021 16:16
Metaclass examples
from collections import defaultdict
from typing import Type, cast, Callable, TypeVar, Any
from functools import wraps
T = TypeVar('T')
def wrap_setattr(definition: dict, fn: Callable) -> Callable:
@wraps(fn)
def wrapped(self, attr, value):
@lrhache
lrhache / sleep.js
Created February 26, 2021 19:26
NodeJs Sleep function
function sleep(n) {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n*1000);
}
@lrhache
lrhache / list.md
Created December 19, 2020 13:07 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@lrhache
lrhache / neo4j-install-ubuntu.sh
Last active March 6, 2018 02:17
neo4j util script
#!/bin/sh
sudo echo "export NEO4J_HOME=/opt/neo4j" >> /etc/environment
source /etc/environment
sudo mkdir -p $NEO4J_HOME
sudo chown ubuntu.ubuntu $NEO4J_HOME
cd /tmp
@lrhache
lrhache / gist:92d8031e8df7f6133257869d775686aa
Created July 26, 2016 15:52
find string in files recursively without touching each files
grep -rl "oldstring" . | LANG=C LC_ALL=C xargs sed -i '' -e "s/oldstring/newstring/g"