Skip to content

Instantly share code, notes, and snippets.

View binho's full-sized avatar

Cleber Santos binho

View GitHub Profile
@jorilallo
jorilallo / UTC Timezones in Django
Last active January 3, 2018 17:10
How to create, store and return timestamps in UTC with Django
from django.utils.timezone import now as utcnow
from calendar import timegm as epoch
# Store in model
created = models.DateTimeField(default=utcnow())
# Get in UTC Epoch
epoch(created.timetuple())
@jmorenoamor
jmorenoamor / download_file.py
Created January 4, 2013 10:42
Download a remote resource using python and requests
# All the magic comes from the requests library http://www.python-requests.org
import requests
# URI of the resource we want to download
FILE_URI = 'http://www.example.com'
# Path to the local file where we will save the remote resource
FILE_NAME = 'downloaded_file.html'
# Chunk size that we will keep in memory, in bytes
@efazati
efazati / title.py
Created January 4, 2013 10:21
flask title decorator, set title easy and simple
from functools import wraps
def title(title=None):
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
g.page_title = title
return f(*args, **kwargs)
return decorated_function
@krzysztofzablocki
krzysztofzablocki / gist:4396302
Last active November 24, 2021 19:17
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )
@vrushank-snippets
vrushank-snippets / PHP : Array To CSV
Created December 12, 2012 11:26
PHP : Array To CSV
/**
* Generating CSV formatted string from an array.
*/
function array_to_csv($array, $header_row = true, $col_sep = ",", $row_sep = "\n", $qut = '"')
{
if (!is_array($array) or !is_array($array[0])) return false;
//Header row.
if ($header_row)
{
@drpancake
drpancake / gist:4265191
Created December 12, 2012 05:56
How to use a block instead of a selector for target-action.
UITapGestureRecognizer *recogizer = [[UITapGestureRecognizer alloc] initWithTarget:^{
NSLog(@"Hello!");
} action:@selector(invoke)];
[myView addGestureRecognizer:recogizer];
@paulirish
paulirish / gist:3910471
Created October 18, 2012 08:33
page visibility API : tribulations with prefixes
// this is the least sucky way i could think of to
// detect and deal with a cross-browser impl of the page visibility api
// forks welcome.
function getHiddenProp(){
var prefixes = ['webkit','moz','ms','o'];
if ('hidden' in document) return 'hidden';
@mattyohe
mattyohe / floatsign.sh
Created October 12, 2012 20:07
A small bash script to re-sign iOS applications.
# !/bin/bash
# Copyright (c) 2011 Float Mobile Learning
# http://www.floatlearning.com/
#
# Extended by Ronan O Ciosoig January 2012
#
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
@paykroyd
paykroyd / gist:3669723
Created September 7, 2012 21:16
Group By in Core Data
NSFetchRequest *request = [self fetchRequestForType:CORE_DATA_BLOCK_TYPE];
NSEntityDescription* entity = [NSEntityDescription entityForName:CORE_DATA_BLOCK_TYPE
inManagedObjectContext:self.managedObjectContext];
NSAttributeDescription* typeDesc = [entity.attributesByName objectForKey:@"type"];
NSExpression *countExpression = [NSExpression expressionForFunction: @"count:"
arguments: [NSArray arrayWithObject:[NSExpression expressionForKeyPath: @"type"]]];
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
[expressionDescription setName: @"count"];
[expressionDescription setExpression: countExpression];
@tony4d
tony4d / p4merge4git.md
Created August 24, 2012 19:00
Setup p4merge as a visual diff and merge tool for git