Skip to content

Instantly share code, notes, and snippets.

Fred Muya muya

Block or report user

Report or block muya

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@muya
muya / yii-actionAdmin.php
Last active Dec 17, 2015
Snippet for Yii's actionAdmin function in the Controller class
View yii-actionAdmin.php
/**
* UsersController actionAdmin function
*/
public function actionAdmin() {
$model = new Users('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Users']))
$model->attributes = $_GET['Users'];
$this->render('admin', array(
@muya
muya / yiiCGridView.php
Last active Dec 17, 2015
Example of a Yii CGridView Widget used in the StudentPortal Project
View yiiCGridView.php
/**
* CGridView widget
*/
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'userID',
'firstName',
@muya
muya / yii-relations.php
Created May 27, 2013
Snippet of a Yii model's relations function
View yii-relations.php
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'studentProfiles' => array(self::HAS_MANY, 'StudentProfiles', 'userID'),
'userGroupMappings' => array(self::HAS_MANY, 'UserGroupMappings', 'userID'),
@muya
muya / minify_on_save.py
Last active Mar 4, 2017
Sublime Text 3 Plugin to Minify JS & CSS files on save (requires bistory's Sublime Minifier here: https://github.com/bistory/Sublime-Minifier)
View minify_on_save.py
import sublime, sublime_plugin
class MinifyOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
file_types_to_minify = ['js', 'css']
filenameParts = view.file_name().split('.')
if filenameParts[len(filenameParts) - 1] in file_types_to_minify:
view.run_command('minify')
@muya
muya / gist:8785e948688a49d83b14
Created Oct 6, 2014
Escaping Liquid Template Tags in Jekyll
View gist:8785e948688a49d83b14
{% highlight html %}
{% raw %}{% if post.excerpt %}{% endraw %}
{% raw %}{{ post.excerpt }}{% endraw %}
{% raw %}{% else %}{% endraw %}
{% raw %}{{ post.content | truncatewords:30 }}{% endraw %}
{% raw %}{% endif %}{% endraw %}
{% endhighlight %}
@muya
muya / peewee_timestamped_model.py
Last active Jul 19, 2019
Timestamped Models in PeeWee
View peewee_timestamped_model.py
from peewee import *
import datetime
database = SqliteDatabase("/data/amazing_people.db", **{})
class BaseModel(Model):
class Meta:
database = database
@muya
muya / logs_organizer.sh
Created May 13, 2015
Rotated Logs Organizer
View logs_organizer.sh
#!/bin/bash
# get first and last .gz
first_file=$(ls *gz|head -1)
last_file=$(ls *gz |tail -1)
echo "first file: "$first_file
echo "last file: "$last_file
@muya
muya / ViewController.swift
Created Jul 18, 2015
swift tutorial imagePickerController problem
View ViewController.swift
//
// ViewController.swift
// FoodTracker
//
// Created by Muya on 14/07/2015.
// Copyright © 2015 muya. All rights reserved.
//
import UIKit
@muya
muya / convert_timestamp_timezone.py
Created Oct 17, 2015
Convert Timestamp Between Timezones
View convert_timestamp_timezone.py
import datetime
from dateutil import parser as date_parser
from dateutil import tz
def convert_timestamp_timezone(timestamp, from_tz="UTC", to_tz="UTC"):
"""
function to convert a string timestamp between timezones
@timestamp - A string timestamp (dateutil.parser will be used to parse)
@from_tz - A string, the current timezone as a string.
@to_tz - A string, the timezone to convert the time to.
Refer to: http://goo.gl/hmPXML for a list of acceptable TZ strings
@muya
muya / logger.py
Created Oct 17, 2015
Configuring multiple loggers in a file
View logger.py
import logging
from logging import FileHandler
from logging import Formatter
LOG_FORMAT = (
"%(asctime)s [%(levelname)s]: %(message)s in %(pathname)s:%(lineno)d")
LOG_LEVEL = logging.INFO
# messaging logger
You can’t perform that action at this time.