Skip to content

Instantly share code, notes, and snippets.

View azakordonets's full-sized avatar

Andrew Zakordonets azakordonets

View GitHub Profile
//remove old unused containers
docker rm -f $(docker ps -a -q)
// remove untagged images
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
@azakordonets
azakordonets / ohMyZshHistoryCleanUp.regex
Created August 29, 2016 09:55
This regular expression allows to remove from .zhs_history all the "trashy" commands that are used commonly and reduce the size of the file
: \d+:0;(gd|gst|gaa|ga|gc|irb|git reset|git stash|newzsh|glg|gb|git push|git init|grm|gl|mc|top|git rebase|ember|rake|rackup|git rm|sensors|rails s|tree|ls|ember install|rubocop|reboot|pry|gitg|gitk|man|unity|bower install|npm install|bundle install|bundle update|git pull|node|jekyll|kill|bin\/console|tmux|la|cd ~/code|nvm|fm|ruby).*\n
{
"cmd": ["babel-node", "$file"],
"selector": "source.js",
"path": "/usr/local/bin:$PATH", // ENV setting for mac users
"quiet": true // get rid of annoying `[Finished in %fs]`
}
{
"values": [
{
"country": "Albania",
"length": "28",
"code": "AL",
"format": "AL2!n8!n16!c"
},
{
"country": "Andorra",
import csv
import json
csvfile = open('test.csv', 'r')
jsonfile = open('file.json', 'w')
def lookahead(iterable):
"""Pass through all values from the given iterable, augmented by the
information if there are more values to come after the current one
(True), or if it is the last value (False).
const dateDiffInMillis = (date1, date2) =>
Math.abs(date2.getTime() - date1.getTime());
const dayDifferenceInSeconds = (date1, date2) =>
Math.round(dateDiffInMillis(date1, date2) / 1000);
const minuteDifferenceBetweenDates = (date1, date2) =>
Math.round(dayDifferenceInSeconds(date1, date2) / 60);
long startTime = System.nanoTime();
method();
long stopTime = System.nanoTime();
long millis = stopTime - startTime;
public String getDurationFormattedString(long startTime, long stopTime) {
final long nanosDifference = stopTime - startTime;
return String.format("%02d min, %02d sec %02d millis",
TimeUnit.NANOSECONDS.toMinutes(nanosDifference),
TimeUnit.NANOSECONDS.toSeconds(nanosDifference) -
@azakordonets
azakordonets / formatJSON.js
Last active January 27, 2016 14:03
If you want nicely to display JSON in your webpage then this is a nice solution for you . http://jsfiddle.net/KJQ9K/554/
function output(inp) {
document.body.appendChild(document.createElement('pre')).innerHTML = inp;
}
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
@azakordonets
azakordonets / formatString.js
Created January 22, 2016 08:29
This is a nice formatter for strings in javascript
+String.prototype.format = function (placeholders) {
+ var s = this;
+ for (var propertyName in placeholders) {
+ var re = new RegExp('{' + propertyName + '}', 'gm');
+ s = s.replace(re, placeholders[propertyName]);
+ }
+ return s;
+};
console.log("Hi my name is ${name} and i'm {$age} years old".format({name: "Andrew", age: "30"}))
@azakordonets
azakordonets / gist:8700e11e8ecf1b247ec0
Created January 12, 2016 09:28 — forked from posaunehm/gist:8300175
call pandoc for JavaScript-Garden. Before running this script - download zip archive, go to doc-> {language} and then run it
pandoc intro/index.md object/general.md object/prototype.md object/hasownproperty.md object/forinloop.md function/general.md function/this.md function/closures.md function/arguments.md function/constructors.md function/scopes.md array/general.md array/constructor.md types/equality.md types/typeof.md types/instanceof.md types/casting.md core/eval.md core/undefined.md core/semicolon.md core/delete.md other/timeouts.md -o Javascript-Garden.epub