Skip to content

Instantly share code, notes, and snippets.

View astagi's full-sized avatar
💫

Andrea Stagi astagi

💫
View GitHub Profile
@stefanfoulis
stefanfoulis / gist:715194
Created November 25, 2010 10:39
django-filer: creating Folders and Files programmatically, If-Modified-Since aware download (quick and dirty)
def download_cover(url, name=None):
#print "========================== START"
#print "==== COVER URL: %s" % (url,)
purl = urlparse(url)
path = purl.path
if path.startswith('/'):
path = path[1:]
abspath = os.path.join(settings.MEDIA_ROOT,settings.RADIOPLAYLIST_COVERS_PREFIX,path)
relpath = os.path.join(settings.RADIOPLAYLIST_COVERS_PREFIX,path)
if not os.path.exists(os.path.dirname(abspath)):
@hikoz
hikoz / dd.py
Created December 15, 2010 04:45
dd with progress in python
#!/usr/bin/env python
import sys
import time
import signal
from subprocess import Popen, PIPE
dd = Popen(['dd'] + sys.argv[1:], stderr=PIPE)
while dd.poll() is None:
time.sleep(.3)
dd.send_signal(signal.SIGUSR1)
@davidnunez
davidnunez / gist:1404789
Created November 29, 2011 13:20
list all installed packages in android adb shell
pm list packages -f
@nalitzis
nalitzis / gist:2667108
Created May 12, 2012 15:11
Unit test with AsyncTask
public class NetworkTasksTest extends InstrumentationTestCase{
public void testGetMedia() throws Throwable{
final Context context = getInstrumentation().getTargetContext();
final CountDownLatch signal = new CountDownLatch(1);
final NetworkTasks networkTasks = new NetworkTasks(context, new GetMediaListener(signal));
runTestOnUiThread(new Runnable() {
@alex
alex / Original lyrics
Created October 1, 2012 04:23
I'm proud to be a unix programmer
If tomorrow all the things were gone,
I’d worked for all my life.
And I had to start again,
with just my children and my wife.
I’d thank my lucky stars,
to be livin here today.
‘ Cause the flag still stands for freedom,
and they can’t take that away.
@andreagrandi
andreagrandi / unmarshall_example.go
Created August 18, 2014 16:18
Example of Unmarshal (from JSON to struct) in Go
package main
import (
"fmt"
"encoding/json"
)
type Message struct {
Name string
Body string
@andreagrandi
andreagrandi / parse_json_post.go
Created August 19, 2014 13:28
Parse a JSON http POST in GoLang
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type test_struct struct {
Test string
@andreagrandi
andreagrandi / linked_circle.py
Last active August 29, 2015 14:23
Python Linked List: prevent the list to become circular
def is_list_circular(l):
slower = l
faster = l.get_next()
while True:
# if faster pointer finds a None element
# then the list is not circular
if (faster is None) or (faster.get_next() is None):
return False
# if faster element catch up with the slower
@ianchen06
ianchen06 / phantomjs_install.sh
Last active April 13, 2019 09:26
How to install PhantomJS on CentOS/RHEL
yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
tar -xjvf ~/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2 --strip-components 1 /opt/phantomjs/
sudo yum install libffi-devel openssl-devel
pip install pyopenssl pyasn1
pip install requests[security]
@flaki
flaki / halloweend.ino
Created November 1, 2015 01:33
Spooky version of the Arduboy rund.ino game (https://github.com/flaki/arduino-rund-ino)
#include <SPI.h>
#include "Arduboy.h"
#include <EEPROM.h>
#include <avr/pgmspace.h>
Arduboy arduboy;
// frame counter
unsigned int frame = 0;