Skip to content

Instantly share code, notes, and snippets.

@pirey
pirey / package.json
Created July 25, 2016 07:02
ionic project with npm script as build tool
{
"name": "generator-ionic-npm",
"version": "1.1.1",
"description": "Ionic app generator for yeoman using npm scripts as build tool",
"scripts": {
"scss": "node-sass --output-style compressed -o www/css src/scss",
"lint": "jshint src",
"concat": "node npm_scripts/concat.js",
"concat-vendor": "node npm_scripts/concat.vendor.js",
"uglify": "uglifyjs www/js/app.bundle.js -c -m -o www/js/app.bundle.min.js",
@pirey
pirey / someservice.spec.js
Last active December 30, 2016 08:03
solution for $httpBackend unexpected requests in jasmine spec for angularjs project
describe('testing using $httpBackend in ionic app', function() {
var yourAsyncService;
var $httpBackend;
// prepare our service and $httpBackend
beforeEach(function() {
// load module that holds our service
// make sure the required module is loaded
module('module_name');
@pirey
pirey / domain_name_pattern.txt
Last active December 30, 2016 08:04
Simple domain name filtering
# including any dots
/^[^\w\d]+|-(?<!\w)+|[^\w\d\.-]+|\s+|_+|[^\w\d]+$/
# match any dots except the last dot before tld
/^[^\w\d]+|-(?<!\w)+|\.(?!\w+$)|[^\w\d\.-]+|\s+|_+|[^\w\d]+$/
@pirey
pirey / functions.php
Last active May 24, 2022 10:52
Wordpress `the_content` filter, for adding class to img element in the page content
<?php
// other stuff ...
// register our filter to the wordpress action 'the_content',
// it will then be called when we call the_content() from anywhere in our template
add_filter( 'the_content', 'add_classlist_to_img' );
function add_classlist_to_img( $content ) {
// used to detect img tag element
$locateElement = '/\<img.*?\/\>/';
@pirey
pirey / functions.php
Last active January 17, 2017 09:50
Get all categories with additional fields in woocommerce
<?php
function wc_get_categories() {
$all_categories = get_categories(array(
'taxonomy' => 'product_cat'
));
foreach ($all_categories as &$cat) {
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$cat->thumbnail_image = wp_get_attachment_url( $thumbnail_id );
$cat->link = get_term_link( $cat->slug, 'product_cat' );
@pirey
pirey / closehtmltag.vim
Last active April 18, 2017 12:12
close html tag properly
" NOTE: change 'input' with tag name
" this will insert '/' before closing the tag
" e.g <input type="text">
" will become <input type="text"/>
%s/\(input.*\)\ze>/\1\/
@pirey
pirey / mejiku.css
Last active June 9, 2017 04:59
basic color names for quick fiddling
.background {
background-color: #efefef;
}
.me {
background-color: tomato;
}
.ji {
background-color: orange;
const filterWhitelist = ar => key => ar.includes(key)
const sliceState = (state, whitelist) => Object.keys(state)
.filter(filterWhitelist(whitelist))
.reduce((sliced, key) => ({ ...sliced, [key]: state[key] }), {})
// usage
const slicer = paths => state => {
const { ui, auth } = state
@pirey
pirey / alacritty-colors.yaml
Created December 5, 2017 03:09
alacritty theme collection
# Colors (Nord)
# colors:
# # Default colors
# primary:
# background: '0x2E3440'
# foreground: '0xD8DEE9'
#
# # Normal colors
# normal:
# black: '0x3B4252'
@pirey
pirey / dst-lambda.zsh-theme
Last active January 23, 2018 06:31
simple zsh theme
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}!"
ZSH_THEME_GIT_PROMPT_CLEAN=""
function prompt_char {
if [ $UID -eq 0 ]; then echo "%{$fg[red]%}#%{$reset_color%}"; else echo λ; fi
}
#PROMPT='%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$(git_prompt_info)