Skip to content

Instantly share code, notes, and snippets.

View mardix's full-sized avatar

Mardix mardix

View GitHub Profile
@mardix
mardix / DOMClass.js
Created December 8, 2018 21:23 — forked from Maksims/DOMClass.js
HTMLElement extension to add, remove, toggle, detect Classes.
HTMLElement = typeof(HTMLElement) != 'undefiend' ? HTMLElement : Element;
HTMLElement.prototype.addClass = function(string) {
if (!(string instanceof Array)) {
string = string.split(' ');
}
for(var i = 0, len = string.length; i < len; ++i) {
if (string[i] && !new RegExp('(\\s+|^)' + string[i] + '(\\s+|$)').test(this.className)) {
this.className = this.className.trim() + ' ' + string[i];
}
@mardix
mardix / python_over_ssh
Created March 21, 2017 07:05 — forked from mattyjones/python_over_ssh
Execute a script located on a remote server over ssh using python
#! /usr/bin/env python
import secure
import pexpect
# the file containing the list of servers to log into
input_file = "script_list"
# The login creds
user = secure.USER
import frontmatter
from frontmatter import Post as FMPost
def frontmatter_to_file(file, data={}, content=""):
p = FMPost(content=content, **data)
with open(file, "w") as f:
f.write(frontmatter.dumps(p))
@mardix
mardix / .vscode-settings.json
Last active March 30, 2017 23:15
My VSCode Settings
{
"python.pythonPath": "/Users/Mardix/.virtualenvs/${workspaceRootFolderName}/bin/python"
}
# Allow to create pages for testing purposes
from datetime import datetime
import random
import string
import shutil
import os
def generateWord():
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):
@mardix
mardix / SASS Responsive mixin
Last active August 29, 2015 14:20
Responsive Mixin
// _responsive_mixin.scss
$font : "Lato", sans-serif;
// Text Colors
$text-color: #111;
$text-light-color: #B9B9B9;
$text-lighter-color: #fff;
$text-dark-color: #1E1E1E;
$text-darker-color: #111;
#!/usr/bin/env python
# coding: utf-8
# You need PIL <http://www.pythonware.com/products/pil/> to run this script
# Download unifont.ttf from <http://unifoundry.com/unifont.html> (or use
# any TTF you have)
# Copyright 2011 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
from image_utils import ImageText
#############################################################################
# current prompt
#############################################################################
# \d – Current date
# \t – Current time
# \h – Host name
# \# – Command number
# \u – User name
# \W – Current working directory (ie: Desktop/)
# \w – Current working directory, full path (ie: /Users/Admin/Desktop)
@mardix
mardix / gist:38895305786610152efa
Created May 5, 2014 18:50
array_map is slower and more of memory hug than foreach in PHP
While I was working on a personal project, I decided to compare foreach vs array_map to iterate over a large set of items.
So to support my decision, I ran a benchmark on both foreach and array_map.
With a simple array of 1,000,000 objects, I iterate over them with foreach and array_map. And surprisingly, foreach ran in 0.24sec average, while array_map took over 3.30sec.
Also array_map ran out of memory, I had to do an ini_set("memory_limit","512M"); to at least get some results.
My system:
Macbook