Skip to content

Instantly share code, notes, and snippets.

@0x1ad2
0x1ad2 / tabs.service.ts
Last active January 15, 2019 00:06
A service to hide and show tabs in Ionic 2
import {Injectable} from '@angular/core';
// Declare TabsService as a provider in app.module.ts
// Inject TabsService in your class: constructor(public tabs: TabsService){}
// Use the this.tabs.hide() or this.tabs.show() methods wherever you want
@Injectable()
export class TabsService {
constructor() {}
public hide() {
@Kyoss79
Kyoss79 / localStorageService.expire.js
Last active April 1, 2019 09:39
Extend the localStorageService for Angular (https://github.com/grevory/angular-local-storage) with the possibility of expiring entries.
/**
* extend the localStorageService (https://github.com/grevory/angular-local-storage)
*
* - now its possible that data stored in localStorage can expire and will be deleted automagically
* - usage localStorageService.set(key, val, expire)
* - expire is an integer defininig after how many hours the value expires
* - when it expires, it is deleted from the localStorage
*/
app.config(($provide) => {
$provide.decorator('localStorageService', ($delegate) => {
@tylerhunt
tylerhunt / active_record_decorator.rb
Created March 19, 2015 18:52
An abstract decorator that allows decorated Active Record records to be assigned to associations without raising an ActiveRecord::AssociationTypeMismatch error.
require 'delegate'
# An abstract decorator useful for decorating Active Record objects.
class ActiveRecordDecorator < SimpleDelegator
# A proxy for the decorator class to allow the delegation of certain class
# methods to the decorated object's class.
class ClassProxy < SimpleDelegator
def initialize(decorator_class, decorated_class)
super decorator_class
self.decorated_class = decorated_class
let(:organisation_customer) do
{
notes: "hot shot lawyer" ,
staff_member_uuid: staff_member.uuid,
created_at: DateTime.now.to_s,
email: customer.email,
name: customer.name,
uuid: "123456"
}
end
@DavidFrahm
DavidFrahm / 020_build_version.js
Last active December 28, 2020 00:05
Cordova build hook, to use build version from config.xml in your hybrid app
#!/usr/bin/env node
// This plugin replaces text in a file with the app version from config.xml.
var wwwFileToReplace = "js/build.js";
var fs = require('fs');
var path = require('path');
var rootdir = process.argv[2];
@ibussieres
ibussieres / upgrade_pg.sh
Last active May 26, 2021 04:29
Upgrade PostgreSQL 9.1 to 9.3 on Ubuntu 12.04
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
@matheusoliveira
matheusoliveira / json_manipulator.sql
Last active February 17, 2024 15:14
Simple PostgreSQL functions to manipulate json objects. (Note: performance is not a concern for those functions)
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
@naoyeye
naoyeye / angular.filters.nl2br.js
Created January 2, 2014 14:36
angular nl2br filter
/*
# Usage in html template:
"xxx | nl2br"
<div ng-bind-html=" YourString | nl2br "></div>
or:
@plentz
plentz / nginx.conf
Last active May 17, 2024 09:08
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@nathancolgate
nathancolgate / Gemfile
Last active January 31, 2023 01:44
How I built a rails interface on top of the amazing IceCube ruby gem. Video of final product: http://youtu.be/F6t-USuWPag
# Add these two gems
gem 'ice_cube', '0.9.3'
gem 'squeel', '1.0.16'