Skip to content

Instantly share code, notes, and snippets.

@franzejr
franzejr / gist:8954754
Last active August 29, 2015 13:56
User error
[21] sharewizz(main)> User.create(id:3989,first_name: "Francisco", last_name:"Lins",terms:true,name:"FranzeJr2", email:"email@gmail.com",password:"password")
(0.2ms) BEGIN
User Load (14.2ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'email@gmail.com' LIMIT 1
User Load (10.5ms) SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = '2df949add7a9e970ff949066f5a6b7105fa42a1c19ea7d245cb54b71f5f1eef5' LIMIT 1
SQL (0.9ms) INSERT INTO `users` (`activated`, `authentication_token`, `bio`, `chat_enabled`, `checked_messages_at`, `checked_notifications_at`, `checked_wizzes_at`, `confirmation_sent_at`, `confirmation_token`, `confirmed_at`, `connected`, `created_at`, `current_sign_in_at`, `current_sign_in_ip`, `deleted_at`, `delta`, `email`, `encrypted_password`, `first_name`, `is_admin`, `is_company`, `language`, `last_name`, `last_sign_in_at`, `last_sign_in_ip`, `name`, `nb_objects`, `password_salt`, `picture`, `rating_average`, `remember_created_at`, `reset_password_sent_at`, `reset_
@franzejr
franzejr / gist:9261112
Created February 27, 2014 22:36
Git branch in prompt
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
@franzejr
franzejr / Load.java
Last active August 29, 2015 14:15
Executing a method from a APK/DEX
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtView = (TextView) findViewById(R.id.result);
try {
//Classes
@franzejr
franzejr / Serialize.java
Last active August 29, 2015 14:22
Serialize objects in Java
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(buffer);
oos.writeObject(objectToBeSerialized);
oos.close();
byte[] rawData = buffer.toByteArray();
//OR
byte[] data = SerializationUtils.serialize(objectToBeSerialized);
@franzejr
franzejr / SampleTest.java
Created June 11, 2015 18:52
Serialize java objects by using Apache Common langs
package test;
import java.io.Serializable;
public class SampleTest implements Serializable {
int age;
String name;
Object o;
public SampleTest(String name, int age, Object o) {
@franzejr
franzejr / gist:181f9ddfd8b7d1ed46e7
Last active August 29, 2015 14:26
Changing postgres password easily

On Windows and OS X, the default password is postgres. But on Linux systems, there is no default password set.

To set the default password: Run the psql command from the postgres user account:

  • sudo -u postgres psql postgres

  • Set the password:

  • \password postgres

@franzejr
franzejr / pom.xml
Created August 4, 2015 18:28
An executable jar with dependencies using Maven
Afterwards you have to switch via the console to the directory, where the pom.xml is located.
Then you have to execute mvn assembly:single and then your executable JAR file with dependencies will be hopefully build.
You can check it when switching to the output (target) directory with cd ./target and starting your jar with a command similiar to java -jar mavenproject1-1.0-SNAPSHOT-jar-with-dependencies.jar.
I tested this with Apache Maven 3.0.3.
@franzejr
franzejr / ad_placement_creator.rb
Created October 4, 2015 18:57
Validations with external services
class AdPlacementCreator
def create(params)
ad = AdPlacement.new(params)
if ad.valid?
ad.short_url = BeaconAPI.shorten(ad.original_url) ad.save
end
end
end
@franzejr
franzejr / transactions_example.rb
Created October 4, 2015 19:00
Using transactions on Active Record - Simple Example
ActiveRecord::Base.transaction do
david.withdrawal(100)
mary.deposit(100)
end
ActiveRecord::Base.transaction do
Statistics.delete_all
Statistics.import_from(csv_file)
end
@franzejr
franzejr / simpleFormPanelExtJS4.js
Created June 10, 2012 22:48
Steps to create a simple form and window in ExtJS4
//OnReady Ext function
Ext.onReady(function(){
//Creating a namespace
Ext.ns("Test");
Ext.define("Test.InformationsFormPanel",
{