Skip to content

Instantly share code, notes, and snippets.

View roalcantara's full-sized avatar
🤖
Don't Panic!

Rogério Rodrigues de Alcântara roalcantara

🤖
Don't Panic!
View GitHub Profile
@roalcantara
roalcantara / gist:2174539
Created March 23, 2012 20:16
SQLServer - importar arquivo CSV
BULK INSERT TB_TEMP --tabela com as mesmas colunas do arquivo CSV
FROM 'C:\Temp\File.csv'-- caminho do arquivo e formato
WITH (
CODEPAGE = 'ACP', -- para arquivos com acento
FIELDTERMINATOR= ';', -- caractere que separa os campos no arquivo
ROWTERMINATOR= '\n') -- referencia para fim da linha
GO
@roalcantara
roalcantara / gist:2206227
Created March 26, 2012 16:15
SQLServer - Procedure com tabela temporária e cursor
USE [BANK]
CREATE PROCEDURE [dbo].[spTbTempAndCursor]
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE #TB_TEMP (
[ID] [varchar](10) NOT NULL,
[NAME] [varchar](10) NOT NULL
@roalcantara
roalcantara / gist:2342555
Created April 9, 2012 09:42
JAVA > Hibernate > Custom Validator Simple Sample
package com.xpto.domain.model.validator;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = PhotoExtensionValidator.class)
@Documented
@roalcantara
roalcantara / gist:2345556
Created April 9, 2012 19:00
JAVA > Hibernate > @Embedded > Custom Column Names
@Embeddable
public class Phone {
private String number;
private String extensionNumber;
//ctors
//getters/setters
}
@roalcantara
roalcantara / gist:2352850
Created April 10, 2012 16:58
Download of Protobuf in Vraptor3
//Controller
@Get
public final Download authenticate() {
AuthenticationProto.Authentication proto = AuthenticationProto.Authentication.newBuilder()
.setToken("token") //sample code
.build();
return new ProtoDownload(proto);
}
@roalcantara
roalcantara / gist:2358538
Created April 11, 2012 10:34
iOS > UIButton Background from url
NSURL* url = [NSURL URLWithString:photoURL];
NSURLRequest* request = [[NSURLRequest alloc] initWithURL: url];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
UIImage* photo = [[UIImage alloc] initWithData:responseData];
[self.btn setImage:photo forState:UIControlStateNormal];
@roalcantara
roalcantara / gist:2425993
Created April 20, 2012 04:23
Easy POST with params and httpheader
//inspiration: http://stackoverflow.com/questions/5269236/http-post-of-uiimage-and-parameters-to-webserver
@implementation HTTPUtils
+(NSData*)post:(NSString*)_urlAddress
params: (NSDictionary*) _params
headers: (NSDictionary*) _headers
images: (NSDictionary*) _images {
// create the connection
@roalcantara
roalcantara / gist:2488964
Created April 25, 2012 11:03
Using BOLL in UIControl
//CustomUIControl.h
@interface CustomUIControl : UIControl
@property (nonatomic, getter=isSelected) BOOL selected;
@end
//CustomUIControl.m
@implementation CustomUIControl
@synthesize selected;
@end
@roalcantara
roalcantara / gist:2656527
Created May 10, 2012 23:22
ASP.NET > Generate a TXT file in memory and download it
byte[] buffer;
using (var memoryStream = new System.IO.MemoryStream())
{
buffer = Encoding.Default.GetBytes("Sample text);
memoryStream.Write(buffer, 0, buffer.Length);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=filename.txt");
Response.AddHeader("Content-Length", memoryStream.Length.ToString());
Response.ContentType = "text/plain"; //This is MIME type
memoryStream.WriteTo(Response.OutputStream);
@roalcantara
roalcantara / MyUITableViewController.h
Created June 14, 2012 07:30
Objective C Block Sample
typedef void (^Completion)(void);//block definition
@interface MyUITableViewController : UITableViewController
@property (nonatomic, copy) NSString* myTitle;
@property (readwrite, copy) Completion completion;
-(MyUITableViewController *)initWithTitle: (NSString *) _myTitle
completion: (Completion) _completion;
-(void)back;