Skip to content

Instantly share code, notes, and snippets.

View gayanvirajith's full-sized avatar
:octocat:

Gayan Virajith gayanvirajith

:octocat:
View GitHub Profile
@gayanvirajith
gayanvirajith / processwire-function-split-results-into-row.php
Last active August 29, 2015 14:04
Sample ProcessWire function usage.
/**
* Returns site feature set markup
* @return String - html markup of features
*/
function getFeatureSet() {
$pages = wire('pages')->find("template=conversion-feature");
if (!count($pages)) return '';
$out = '';
$config = wire('config');
$perPage = 3;
@gayanvirajith
gayanvirajith / box-sizing.css
Last active August 29, 2015 14:04
CSS box-sizing best practice
// Credit Source:
// http://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/
// --------------------------------------------
// box-sizing to border-box
// --------------------------------------------
html {
box-sizing: border-box;
@gayanvirajith
gayanvirajith / config
Created July 17, 2014 05:16
Automate push on gh-pages and master branches. Add following lines to the [remote "origin"] section of your .git/config
push = refs/heads/master:refs/heads/gh-pages
push = refs/heads/master:refs/heads/master
@gayanvirajith
gayanvirajith / iptable-restore.md
Last active August 29, 2015 14:04
Restore saved iptable config on fedora 19

Step 1

Go to terminal

Shortcut key: alt+f2 (type: gnome-terminal)

Step 2

Gain root access by having following command (it will ask your root password).

@gayanvirajith
gayanvirajith / find-using-grep.md
Last active August 29, 2015 14:04
Find all files containing a text string on Linux.

grep -Ril "text-to-find-here" "directory path"

  • i stands for upper/lower case (optional in your case).
  • R stands for recursive.
  • l stands for "show the file name, not the result itself`.

grep -rnw 'directory' -e "pattern" # this works for me all the time.

  • r is recursive
  • n is line number
@gayanvirajith
gayanvirajith / all_dbs.sql
Created July 29, 2014 09:56
Export all MySQL databases at once
mysqldump -u root -p --all-databases > all_dbs.sql
@gayanvirajith
gayanvirajith / command-to-compile-c++-programs.md
Created July 29, 2014 18:15
Command to compile and run C++ programs in ubuntu

g++ foo.c where foo.c is the name of the program to be compiled. This will produce an executable in the same directory called a.out which you can run by putting this in your terminal - ./a.out

g++ -o output foo.c This will compile foo.c and you can type ./output to run the compiled code.

@gayanvirajith
gayanvirajith / checkDbConnection.php
Last active August 29, 2015 14:04
Check MySQL db connection in php
<?php
/**
* Checking the MySQL connection
*/
// Host name
$host = "localhost";
// MySQL username
$username = "databaseusername";
@gayanvirajith
gayanvirajith / Preferences.sublime-settings
Created August 21, 2014 10:44
My Sublime text 3 settings
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_size": 11,
"hot_exit": false,
"ignored_packages":
[
"Vintage"
],
"remember_open_files": false,
"rulers": [80],
@gayanvirajith
gayanvirajith / bypass.js
Created August 30, 2014 13:53
Bypass the cache for mobile and tablet-devices
var nocache = $.cookie('nocache');
if($(window).width() < 768) {
if(nocache === null) {
// set nocache cookie to bypass ProCache
$.cookie('nocache', 1, { path: '/' } );
// do a redirect back to current page to bypass ProCache
window.location.href = './';
}
} else if(nocache != null) {
// re-enable ProCache as window width >= 768