Skip to content

Instantly share code, notes, and snippets.

View zakelfassi's full-sized avatar

zak elfassi zakelfassi

View GitHub Profile
@zakelfassi
zakelfassi / android_shortcut.java
Created April 10, 2014 21:03
Create android app shortcut programatically
// Note that a shortcut is created automagically if the app is installed via Play store.
// Change "APP_NAME" by your app name. *MrObvious*
/*Manifest file - add this */
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
/* MainActivity.java */
public class MainActivity ... {
...
private SharedPreferences appSettings;
@zakelfassi
zakelfassi / lastEdited.sh
Created February 15, 2016 17:45
Get Last 1000 edited files in Unix
find . -type f -printf '%T@ %p\n' | sort -n | tail -1000 | cut -f2- -d" "
@zakelfassi
zakelfassi / gist:8676166
Created January 28, 2014 20:52
Rollback a `git commit`
Undo a commit and redo
$ git commit ... (1)
$ git reset --soft 'HEAD^' (2)
$ edit (3)
$ git add .... (4)
$ git commit -c ORIG_HEAD (5)
This is what you want to undo
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes may or may not be required in your shell)
@zakelfassi
zakelfassi / .htaccess-redirect
Created December 21, 2013 17:05
Super PHP site redirection.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^OLD_SITE.com [nc]
rewriterule ^(.*)$ http://NEW_SITE.com/$1 [r=301,nc]
</IfModule>
@zakelfassi
zakelfassi / Heroku-migration.sh
Created October 23, 2013 05:44
Adding a new Heroku app fork.
git remote add forked git@heroku.com:NEW_APP_NAME.git
git remote rename heroku old
git remote rename forked heroku
git push heroku master
heroku labs:enable user-env-compile -a NEW_APP_NAME
@zakelfassi
zakelfassi / Rails-assets_sync-cheatsheet.rb
Created October 11, 2013 03:16
Rails S3 assets_sync configuration cheatsheet
# gemfile
gem 'asset_sync'
# application.rb
config.assets.initialize_on_precompile = true
config.assets.precompile += ['stuff.js', 'stuff.css']
# production.rb
config.assets.enabled = true
@zakelfassi
zakelfassi / set-font-size.js
Last active December 23, 2015 17:09
Do you ever feel the need to adjust the font-size of a page ? Just run this code in your Console (Chrome dev tools/Firebug/...) and select some text ! // note that this code was written under 60seconds just to read this post : http://lifehacker.com/a-scientific-guide-to-saying-no-1293242273 Chrome extension coming soon. Maybe.
(function() {
function setSelectedSize(s) {
var arr = document.getElementsByTagName(window.getSelection().baseNode.parentNode.tagName);
for(var i=0; i<arr.length; i++) {
arr[i].style.fontSize = "" + s + "px";
}
}
window.addEventListener("mouseup", function() {
if(window.getSelection().type == "Range") {
@zakelfassi
zakelfassi / update_paperclip_attachements.rb
Created September 26, 2014 12:54
Move Paperclip attachements
# Assuming you had a model like this
#
# class Post
# has_attached_file :image, :path => ":rails_root/public/system/:attachment/:id/:style/:filename"
# end
namespace :paperclip do
desc "Recreate attachments and save them to new destination"
task :move_attachments => :environment do
# GIT Tricks.
Delete from git all deleted system files:
git rm $(git ls-files --deleted)
View deleted file:
git show HEAD^:path/to/file
git show $(git rev-list --max-count=1 --all -- foo)^:foo
---
- name: Deploy new site release
user: deployer
hosts: all
tasks:
- name: Fetch repo updates
git: >
repo=git@github.com:my/repo.git