Skip to content

Instantly share code, notes, and snippets.

View scodx's full-sized avatar
🏠
Working from home

Oscar Sánchez scodx

🏠
Working from home
View GitHub Profile
@scodx
scodx / media-query.css
Created August 19, 2019 22:53 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@scodx
scodx / intercept-ajax.js
Created July 8, 2019 18:27
intercept ajax request on JS
var oldXHROpen = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
if (url.indexOf('getVideo') >= 0) {
this.addEventListener('load', function() {
console(this.responseText);
});
return oldXHROpen.apply(this, arguments);
}
}
@scodx
scodx / mysql-utc-fixe.md
Created May 16, 2019 14:49
MySQL connection refused, happened on PHPStorm and Datagrid

Background

If you are using a java app that tries to connect to a MySQL/MariaDB database and gets this error:

java.sql.SQLException: The server timezone value 'UTC' is unrecognized or represents more than one timezone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc timezone value if you want to utilize timezone support.

it seems that the app is not sending the correct timezone params, you might want to add this to the connection string:

jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

Note that just passing serverTimezone=UTC fixed the problem, but it might require the other params.

@scodx
scodx / features-drupal-7.md
Created May 15, 2019 17:43
Managing features in Drupal 7 & Drush

Add component to a feature

List components to locate the one you want to add, it will also list the components already tied to a feature, pass --exported to list only these.

drush fc

Next, drush fe feature_name variable:foo_var views_view:foo_view. You can pass as many as you like

will update, or create, a module named foo_feature. The output from drush fc can be used to populate the required component:name syntax.

@scodx
scodx / ajax-cross-origin.md
Last active May 8, 2019 21:36
Enable cross origin requests

You can control this via HTTP header by adding Access-Control-Allow-Origin. Setting it to * will accept cross-domain AJAX requests from any domain.

Using PHP it's really simple, just add the following line into the script that you want to have access outside from your domain:

header("Access-Control-Allow-Origin: *");

or whatever methods you have available in libraries like Guzzle or Http Foundation to manage HTTP requests

Don't forget to enable mod_headers module in httpd.conf.

To disable entering the sleep mode I had to edit the /etc/systemd/logind.conf file and modify the line:

HandleLidSwitch=suspend

to

HandleLidSwitch=ignore

then

@scodx
scodx / git patches.md
Last active November 11, 2019 16:38

Git Patches

Generate a patch from un-commited files:

git diff > file.patch

But sometimes it happens that part of the stuff you're doing are new files that are untracked and won't be in your git diff output. So, one way to do a patch is to stage everything for a new commit (but don't do the commit), and then:

git diff --cached > file.patch

Add the 'binary' option if you want to add binary files to the patch (e.g. mp3 files):

Executive Summary

$ git push --delete <remote_name> <branch_name>
$ git branch -d <branch_name>

Note that in most cases the remote name is origin.

Delete Local Branch

To delete the local branch use one of the following:

Assuming that your branch is called master both here and remotely, and that your remote is called origin you could do:

git reset --hard <commit-hash>
git push -f origin master

Use the other answers if you don't mind losing local changes. This method can still wreck your remote if you choose the wrong commit hash to go back to.

If you just want to make the remote match a commit that's already in your local branch: