Skip to content

Instantly share code, notes, and snippets.

View umar-webonise's full-sized avatar

Umar Siddiqui umar-webonise

View GitHub Profile
@umar-webonise
umar-webonise / dynamice_active_model_serializers.rb
Last active August 29, 2015 14:19
Dynamic Fields for active_model_serializers
class YourDynamicModelSerializer < ActiveModel::Serializer
attributes :_id, :name
def _id
object._id.to_s
end
def attributes
fields = object.attributes
@umar-webonise
umar-webonise / gist:8d5921b1892a3bff0931
Created April 10, 2015 10:10
Multi select drop down with tree indentation
<div class="control labelMove bottomSpace4">
<select
id="org_node"
name="orgNode"
class="chosen-select"
chosen="treeDropOptions"
required
ng-model="indicator.org_node_id">
<option ng-repeat="opt in treeDropOptions" ng-value="opt.id">
{{Array(opt.lvl * 7).join("&nbsp;")}} {{opt.name}}
@umar-webonise
umar-webonise / units_seed_data
Created March 31, 2015 14:34
Seed Data for adding units for dynamice forms
unit_types = [
{ name: 'length' },
{ name: 'area' },
{ name: 'weight' },
{ name: 'volume' }
].each do |tag_info|
puts "Added #{UnitType.create(tag_info).inspect}"
end
@umar-webonise
umar-webonise / csv to array
Created March 10, 2015 12:58
CSV to Array
factory.CSVtoArray = function (text) {
var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
// Return NULL if input string is not well formed CSV string.
if (!re_valid.test(text)) return null;
var a = []; // Initialize array to receive values.
text.replace(re_value, // "Walk" the string using replace with callback.
function(m0, m1, m2, m3) {
// Remove backslash from \' in single quoted values.
if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
@umar-webonise
umar-webonise / gist:73641a253a03d405e64e
Created March 5, 2015 09:15
chonse jquery and angular js directive
TreeniApp.directive('chosen', function() {
var linker = function(scope, element, attr) {
// update the select when data is loaded
scope.$watch(attr.chosen, function(oldVal, newVal) {
element.trigger('chosen:updated');
});
// update the select when the model changes
scope.$watch(attr.ngModel, function() {
element.trigger('chosen:updated');
@umar-webonise
umar-webonise / tit_for_tat
Last active August 29, 2015 14:15
Tit For Tat Solution
(1..100).each do |num|
result = 'Tit' if num % 3 == 0
if num % 5 == 0
result &&= result + 'ForTat'
result ||= 'Tat'
end
result ||= num
puts result
end