Skip to content

Instantly share code, notes, and snippets.

View franzejr's full-sized avatar
💻
writing code

Franze M franzejr

💻
writing code
  • Remote
  • 02:13 (UTC -03:00)
View GitHub Profile
@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 / remove_trailing_whitespace.sh
Last active April 5, 2017 21:30
Removing trailing whitespace recursively from your project
#Removing trailing whitespace from .rb files
find -name '*.rb' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -i
#Removing trailing whitespace from .erb files
find -name '*.erb' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -i
# WORKING ON OSX
find . \( -name '*.rb' -or -name '*.js' -or \\n-name '*.css' -or -name '*.scss' -or -name '*.erb' -or -name '*.yml' -or -name '*.erb' \) \\n-print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
@franzejr
franzejr / remove-trailing-whitespace.sh
Last active October 23, 2015 12:18
Remove Trailing whitespace - pre-commit hook - forked from @imoldman
#!/bin/bash
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
# For install:
# copy this file to ~/some_project/.git/hooks/pre-commit and give it permission of execution
# detect platform
fibonacci = Hash.new{ |numbers,index|
numbers[index] = fibonacci[index - 2] + fibonacci[index - 1]
}.update(0 => 0, 1 => 1)