Skip to content

Instantly share code, notes, and snippets.

View mallamanis's full-sized avatar
:octocat:

Miltos mallamanis

:octocat:
View GitHub Profile
@mallamanis
mallamanis / noListComp.ql
Last active April 30, 2020 17:24
Use generator expression instead of list comprehension
/**
* @name Prefer Generator to List Comprehension
* @description List comprehensions can be avoided in favor of
* @kind problem
* @tags reliability
* maintainability
* @problem.severity recommendation
* @sub-severity low
* @precision medium
* @id py/no-list-comprh
@mallamanis
mallamanis / aliases.sh
Last active May 16, 2019 09:14
Read json[l] files
function zjson {
zcat $1 | python3 -m json.tool | less
}
function zjsonl {
zcat $1 | while read -r l; do
echo $l | python3 -m json.tool
echo '--------------------------------------------------'
done | less
}
@mallamanis
mallamanis / scan_all_states.py
Created April 6, 2016 12:39
Stupid simple Theano example that allows using all previous states in a `scan`
in_seq = T.matrix(name='input')
initial_state = theano.shared(np.array([0., 0.]), name='initial')
initial_scan_state = T.zeros((in_seq.shape[0], initial_state.shape[0]))
initial_scan_state = T.set_subtensor(initial_scan_state[0], initial_state)
def fun(i, current_element, state):
res = T.sum(state[:i], axis=0)+current_element
return T.set_subtensor(state[i], res)
@mallamanis
mallamanis / parallelize.sh
Created February 17, 2016 15:08
Run jobs in parallel (in bash) limiting the number of jobs
#!/bin/bash
#
# From https://yoursunny.com/t/2016/parallelize/
#
# Run commands in parallel.
# Usage: JOBS=8 ./parallelize.sh < commands.lst
# JOBS: number of subprocesses
# If omitted, use number of CPUs.
# If specified as AxB, A subprocesses are running in parallel,
# and JOBS environ passed to subprocesses is B.
@mallamanis
mallamanis / gettopprojects.py
Last active December 22, 2017 15:35
Get top projects from GHTorrent
#!/usr/bin/python
import csv, sys, os
import numpy as np
# Get the top X non-fork projects for the GHTorrent dump (without using SQL)
# The dumps should be available at http://ghtorrent.org/downloads.html
if len(sys.argv) < 5:
print "Usage <dir> <language> <topX> <outcsv>"
sys.exit(-1)
@mallamanis
mallamanis / .htaccess
Created May 29, 2014 13:41
force https
#put the code below into your .htaccess file to force https
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://lowesthost.com%{REQUEST_URI} [R,L]
@mallamanis
mallamanis / gist:5170610
Created March 15, 2013 15:20
Get all java files in a tar
find ./java_projects -iname '*.java' -print | tar -zcvf java_projects.tar.gz --files-from -
@mallamanis
mallamanis / gist:3895288
Created October 15, 2012 20:39
Eclipse get AST of Java
/**
*
*/
package uk.ac.ed.inf.astretriever;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Map;
@mallamanis
mallamanis / gist:2466882
Created April 22, 2012 20:57
Batch download files (.jpg) with consecutive numbering
import urllib2
prefix = "url-pref"
for i in xrange(1,7882):
filename = '%0*d' % (5,i)+'.jpg'
url = prefix + filename
print url
u = urllib2.urlopen(url);
localfile = open(filename , 'w')
@mallamanis
mallamanis / gist:1988064
Created March 6, 2012 18:35
Convert string to GSM (SMS) compatible encoding
function convertToGSM($t){
$t = strtr($t, array(
"@" => "%00",
"£" => "%01",
"$" => "%02",
"¥" => "%03",
"è" => "%04",
"é" => "%05",
"ù" => "%06",
"ì" => "%07",