Skip to content

Instantly share code, notes, and snippets.

View hperantunes's full-sized avatar

Hilton Perantunes hperantunes

  • Montreal, Canada
View GitHub Profile
// Newlines, tabs and non-printable unicode characters
private static final String sanitizePattern = "(\\r|\\n|\\t|\\p{C})";
private static final String whitespacePattern = " +";
private static final String replacementString = " ";
private static String sanitize(String text) {
return text.replaceAll(sanitizePattern, replacementString);
}
{
"editor.tabSize": 2,
"editor.renderWhitespace": "none",
"workbench.iconTheme": "vs-seti",
"editor.minimap.enabled": true,
"terminal.integrated.shell.windows": "c:\\windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k",
"c:\\program files\\git\\bin\\bash.exe"
],
@hperantunes
hperantunes / rename.ps1
Created February 22, 2017 15:13
Powershell batch rename files; remove whitespace and parentheses
Dir | Rename-Item –NewName { $_.name.replace(' ','_') -replace '[()]','' }
@hperantunes
hperantunes / sanitize_json_response_with_password.sh
Last active December 28, 2016 19:19
Sanitizes some JSON response by replacing values
echo '{"somePassword": "password", "someSecret": "secret", "somethingElse": unchanged"}' \
| sed '/\(Password": *"\|Secret": *"\)[^"]*\("\)/ s//\1*****\2/g'
# {"somePassword": "*****", "someSecret": "*****", "somethingElse": unchanged"}
@hperantunes
hperantunes / recover-last-queries.sql
Last active June 15, 2017 14:40
Get all queries executed against the server (SQL Server)
-- Accidently closed an unsaved tab in SQL Server Management Studio, losing my query
-- Found out you can get all queries ran against the server:
SELECT
execquery.last_execution_time AS [Date Time],
execsql.text AS [Script]
FROM
sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY
public static class DictionaryExtension
{
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) where TValue : class
{
TValue value;
return dictionary.TryGetValue(key, out value)
? value
: default(TValue);
}
}
@hperantunes
hperantunes / tail-grep.ps1
Created February 25, 2016 16:45
tail + grep powershell equivalent
Get-Content C:\temp\mylogfile.log -tail 100 –wait | Select-String 'search'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
(function () {
var dice = (function (name) {
var root = typeof window !== 'undefined' ? window : global,
had = Object.prototype.hasOwnProperty.call(root, name),
prev = root[name],
me = root[name] = {};
if (typeof module !== 'undefined' && module.exports) {
module.exports = me;
}
me.noConflict = function () {
// http://stackoverflow.com/a/14794066/136381
function isInt(value) {
var x;
if (isNaN(value)) {
return false;
}
x = parseFloat(value);
return (x | 0) === x;
}