Skip to content

Instantly share code, notes, and snippets.

Avatar

Syamil MJ syamilmj

  • Kuala Lumpur, Malaysia
View GitHub Profile
@syamilmj
syamilmj / http.ex
Created Dec 15, 2016
HTTP Client base
View http.ex
defmodule Crux.Http do
use HTTPoison.Base
def process_url(url) do
Application.get_env(:crux, :api) <> url
end
def process_request_body(body) when is_map(body) do
Poison.encode!(body)
end
@syamilmj
syamilmj / enum.ex
Created Oct 29, 2016
Add enum datatype support to Ecto
View enum.ex
defmodule Inventory.Enum do
@moduledoc """
Provides macro to support Enum datatype with Ecto
## Usage
In your model:
import Inventory.Enum
View rails_cheatsheet.md

An incomplete cheatsheet for rails 3. Things are added as they are required.

Active Record validations

# http://guides.rubyonrails.org/active_record_validations_callbacks.html

class SomeClass < ActiveRecord::Base

  # length
@syamilmj
syamilmj / 0_reuse_code.js
Created Feb 18, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View gist:6108795
<?php get_header(); ?>
<?php get_template_part( 'includes/contents/content', 'stream'); ?>
<?php get_template_part( 'includes/contents/content', 'index' ); ?>
<?php get_footer(); ?>
View meta-boxes.php
<?php
/**
* Posts & Pages meta boxes
*/
/**
* Main custom meta boxes class
*/
if(!class_exists('AQ_Meta_Boxes')) {
@syamilmj
syamilmj / gist:4442840
Created Jan 3, 2013
template-portfolio.php
View gist:4442840
<?php
/*
Template Name: Portfolio
*/
$column = strtolower($data['aq_portfolio_layout']); //Get number of columns
get_header(); ?>
<div id="content-full-width" class="cf">
@syamilmj
syamilmj / styles.php
Created Nov 15, 2012
disable bg patterns
View styles.php
/** line 125 */
background: <?php echo $data['header_bg_color'] ?> url(<?php echo $data['header_bg_img'] ?>);
// Change to:
background: <?php echo $data['header_bg_color'] ?>;
/** line 169 */
@syamilmj
syamilmj / gist:4009718
Created Nov 4, 2012
options.css enqueue
View gist:4009718
if(is_multisite()) {
$uploads = wp_upload_dir();
wp_register_style('options', $uploads['baseurl'] . '/options.css', 'style');
} else {
wp_register_style('options', get_template_directory_uri() . '/css/options.css', 'style');
}
View generate_options_css.php
function generate_options_css($newdata) {
/** Define some vars **/
$data = $newdata;
$uploads = wp_upload_dir();
$css_dir = get_template_directory() . '/css/'; // Shorten code, save 1 call
/** Save on different directory if on multisite **/
if(is_multisite()) {
$aq_uploads_dir = trailingslashit($uploads['basedir']);