Skip to content

Instantly share code, notes, and snippets.

View malexandre's full-sized avatar

Marc Alexandre malexandre

View GitHub Profile
@malexandre
malexandre / xls-to-xlsx-conversion.py
Last active October 28, 2021 18:58
Convert xls file to xlsx in python
import xlrd
from openpyxl.workbook import Workbook as openpyxlWorkbook
# content is a string containing the file. For example the result of an http.request(url).
# You can also use a filepath by calling "xlrd.open_workbook(filepath)".
xlsBook = xlrd.open_workbook(file_contents=content)
workbook = openpyxlWorkbook()
for i in xrange(0, xlsBook.nsheets):
@malexandre
malexandre / base.js
Last active November 9, 2017 14:21
Solutions to manage big classes through multiple files for modularity
export defaut MyBigClass extends MyParent {
constructor() {
super()
}
method1() {
// ...
}
method2() {
@malexandre
malexandre / index.js
Last active August 9, 2017 09:19
Gif or emojis ?
var server = require('./server/server')
server.run()
@malexandre
malexandre / update_socket.py
Last active February 28, 2017 16:27
Update google/appengine/dist27/socket.py as per https://code.google.com/p/googleappengine/issues/detail?id=12783
content = ''
with open('/google-cloud-sdk/platform/google_appengine/google/appengine/dist27/socket.py', 'rb') as fd:
content = fd.read()
content = content.replace('from _ssl import RAND_add, RAND_egd, RAND_status, SSL_ERROR_ZERO_RETURN, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE, SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_SYSCALL, SSL_ERROR_SSL, SSL_ERROR_WANT_CONNECT, SSL_ERROR_EOF, SSL_ERROR_INVALID_ERROR_CODE',
'''from _ssl import \\
RAND_add, \\
RAND_status, \\
SSL_ERROR_ZERO_RETURN, \\
SSL_ERROR_WANT_READ, \\
SSL_ERROR_WANT_WRITE, \\
@malexandre
malexandre / controller.js
Last active January 25, 2016 16:45
AngularJS Convention
(function()
{
'use strict';
angular
.module('Controllers')
.controller('MyController', MyController);
/* @ngInject */
function MyController($scope, MyService)
@malexandre
malexandre / gist:3934578
Created October 22, 2012 21:34
Bash function for Jekyll to create drafts & publish them
function draft()
{
local editor=""
local title=""
while test $# -gt 0; do
case "$1" in
-c)
editor="$2"
shift
shift
@malexandre
malexandre / Rakefile
Created October 22, 2012 15:07
Rakefile for Jekyll with draft & publish management
require 'date'
desc "Given a title as an argument, create a new post file"
task :draft, :title do |t, args|
puts "Creating _drafts/#{args.title}"
filename = "#{args.title.gsub(/\s/, '_').downcase}.markdown"
path = File.join("_drafts", filename)
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
File.open(path, 'w') do |file|
file.write <<-EOS
@malexandre
malexandre / gist:8379c68ed4ea92ed465a
Created July 2, 2015 14:32
Use a dict to replace a group of text in a string in python
import re
s = "string to replace with KEY1 and KEY2, but also KEY3. But KEY5 is not defined in the replacements dict."
pattern = re.compile(r'\b(' + '|'.join(replacements.keys()) + r')\b')
replacements = {
'KEY': 'VALUE',
'KEY2': 'VALUE2',
'KEY3': 'VALUE3',
'KEY4': 'VALUE4'
@malexandre
malexandre / gist:b29f26b9912c82230ee6
Created July 2, 2015 14:29
Copy the content of a docx inside another in python app engine
from server.api.drive import Drive
from server.libs.docx import Document
from cStringIO import StringIO
driveFile = Drive.getFile('DRIVE_ID')
doc = Document(StringIO(Drive.downloadFile(driveFile['downloadUrl'])))
doc_to_copy = Document(StringIO(Drive.downloadFile(Drive.getFile('DRIVE_ID_TO_COPY')['downloadUrl'])))
for element in doc_to_copy._body._element:
doc._body._element.append(element)
@malexandre
malexandre / copyList.js
Created December 18, 2014 17:03
Copy an array into another that already exists (like 'dest = src;', except that it keeps the reference to the existing array)
function copyArray(src, dest)
{
// (performance: http://jsperf.com/empty-javascript-array & http://jsperf.com/array-extending-push-vs-concat)
while(dest.length > 0)
{
dest.pop();
}
if (src)
{
for (var i = 0; i < src.length; ++i)