Skip to content

Instantly share code, notes, and snippets.

@oppara
oppara / gist:132274
Created June 18, 2009 23:13
php: mb_trim
function mb_trim( $str ) {
return mb_ereg_replace(
'^[[:space:]]*([\s\S]*?)[[:space:]]*$', '\1', $str );
}
@robspychala
robspychala / redis_webhook
Created April 26, 2011 16:32
Simple example of a redis based webhook implementation. (gist has external dependancies, but they should be easy to remove)
#!/usr/bin/env python2.6
import sys, urllib2, urllib, time, threading, signal
sys.path.append('support/lib')
import settings
from settings import logging
from lib import taskqueue
@waynemoore
waynemoore / month_day_range.py
Created July 27, 2011 11:01
Get first and last day of a particular month using python-dateutil.
import datetime
# requires python-dateutil (http://labix.org/python-dateutil)
from dateutil.relativedelta import relativedelta
def get_month_day_range(date):
"""
For a date 'date' returns the start and end date for the month of 'date'.
Month with 31 days:
@bergantine
bergantine / gist:1171682
Last active July 11, 2023 01:42
Python Image Encoding in Data URI Scheme Base 64. #python #base64
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "")
# HTML Image Element
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
# CSS Background Image
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri)
print css
@thiagoghisi
thiagoghisi / CodingDojo_DicasParaNovosGrupos
Created September 30, 2011 23:24
Tutorial/Dicas para montar um grupo de Coding Dojo na sua região
1ª Criar um grupo de discussão; (Sugestão: Google Groups)
2ª Divulgar o grupo para o pessoal da sua região nas redes socias que você participa;
(Dica: Divulgação no Twitter é essencial)
3ª Fazer um spam para todos os seus contatos da área da sua região convidando para o grupo;
4ª Se você não for muito influente nas redes sociais ou não tiver muitos contatos,
solicitar para alguém que tenha ajudar na divulgação do grupo;
(Dica: O que vale nesse momento é fazer bastante barulho)
@MikeRogers0
MikeRogers0 / validate-email.php
Created June 16, 2012 17:09
How to validate an email address with PHP
<?php
function validEmail($email){
// Check the formatting is correct
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return FALSE;
}
// Next check the domain is real.
$domain = explode("@", $email, 2);
return checkdnsrr($domain[1]); // returns TRUE/FALSE;
@MercuryRising
MercuryRising / redisCache.py
Created October 13, 2012 20:06
Caching Files
import redis
import time
import random
def load_file(fp, fpKey, r, expiry):
with open(fp, "rb") as f:
data = f.read()
p = r.pipeline()
p.set(fpKey, data)
@mrkline
mrkline / c_sharp_for_python.md
Last active July 21, 2024 08:51
An intro to C# for a Python developer. Made for one of my coworkers.

C# For Python Programmers

Syntax and core concepts

Basic Syntax

  • Single-line comments are started with //. Multi-line comments are started with /* and ended with */.

  • C# uses braces ({ and }) instead of indentation to organize code into blocks. If a block is a single line, the braces can be omitted. For example,

@staltz
staltz / introrx.md
Last active July 26, 2024 04:24
The introduction to Reactive Programming you've been missing
@alexaleluia12
alexaleluia12 / Java.java
Last active February 11, 2024 12:05
Benchmarck (comparação de velocidade) Python, C, Java, Javascript, C++, Kotlin, Go
public class Java {
public static void main(String[] args) {
int count = 0;
for(int i=0; i<1000; i++){
count += i;
}
System.out.println(count); // corrigido conforme comentario
}
}