Skip to content

Instantly share code, notes, and snippets.

View lerua83's full-sized avatar

Alvaro Leon lerua83

  • Esslingen am Neckar
View GitHub Profile
@lerua83
lerua83 / getFileOtherBranch.txt
Created November 14, 2013 10:08
GIT - How to get just one file from another branch URL: http://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch I am using git and working on master branch. This branch has a file called app.js . I have an experiment branch in which I made a bunch of changes and tons of commit. Now I want to bring all the changes …
git show experiment:path/to/app.js
git show experiment:path/to/app.js > path/to/app.js /* In order to copy the file of expermient branch to our current branch */
@lerua83
lerua83 / restoreDeletedFileFromRepo.txt
Created November 14, 2013 08:48
GIT - Restore a deleted file in a Git repo URL: http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file.
/* Find the last commit that affected the given path. As the file isn't in the HEAD commit, this commit must have deleted it.*/
git rev-list -n 1 HEAD -- <file_path>
// Then checkout the version at the commit before
git checkout <deleting_commit>^ -- <file_path>
##############################################################################################
for (var key in p) {
if (p.hasOwnProperty(key)) {
alert(key + " -> " + p[key]);
}
}
@lerua83
lerua83 / isObjectEmpty.js
Created November 14, 2013 08:45
Javascript - How to know if an object is Empty URL: http://stackoverflow.com/questions/4994201/is-object-empty Assuming that by empty means "has no properties of its own"
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
function is_empty(obj) {
// null and undefined are empty
if (obj === null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0) return false;
@lerua83
lerua83 / onToggleClassCompleteFallback.js
Created November 14, 2013 08:43
jQuery - Function on toggleClass complete URL: http://stackoverflow.com/questions/10321393/jquery-function-on-toggleclass-complete How can I do a function once a toggleClass has completed? The .toggleClass method along with all other animation methods return a deferred object that you can access using .promise(). At that point, you can bind to i…
$("#loader").toggleClass('fadeOut',600).promise().done(function(){
alert('a');
});
@lerua83
lerua83 / commitsTwoDates.txt
Created November 13, 2013 13:22
GIT - Get the commits that occured between two dates URL: http://stackoverflow.com/questions/1161609/in-git-how-can-i-get-the-diff-between-all-the-commits-that-occured-between-two How to obtain all the commits that occurred between two dates
git whatchanged --since="2 year ago" --until="1 year ago" [--author="NAME_OF_THE_AUTHOR"]
@lerua83
lerua83 / extractNumbersString.php
Created November 13, 2013 13:20
PHP - Extract numbers from a string: URL: http://stackoverflow.com/questions/6278296/extract-numbers-from-a-string I want to extract the numbers from a string that contains numbers and letters like
$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
@lerua83
lerua83 / validateDate.js
Created November 13, 2013 12:49
URL: http://stackoverflow.com/questions/1433030/validate-number-of-days-in-a-given-month How would you validate the number of days in a given month?
function validateDate( intDay, intMonth, intYear )
{
return intMonth >= 1 && intMonth <= 12 && intDay > 0 && intDay <= daysInMonth( intMonth, intYear );
}
function daysInMonth( intMonth, intYear )
{
switch ( intMonth )
{
case 2:
@lerua83
lerua83 / calculateGermanHolidays.php
Created November 13, 2013 12:46
Der folgende Codeschnipsel enthält keinerlei Überprüfungen der übergebenen Parameter, diese sollten für den produktiven Einsatz noch nachgepflegt werden. Wie man sieht, ist die Berechnung von Wochendenden und Feiertagen recht einfach. Diese Berechnung kann man sicherlich auch schnell in anderen Programmiersprachen abbilden.
function freierTag($tag, $monat, $jahr)
{
// Parameter in richtiges Format bringen
if(strlen($tag) == 1) {
$tag = "0$tag";
}
if(strlen($monat) == 1) {
$monat = "0$monat";
}