Skip to content

Instantly share code, notes, and snippets.

View pierrejoubert73's full-sized avatar

Pierre Joubert pierrejoubert73

View GitHub Profile
@jens1101
jens1101 / data-url.js
Last active October 3, 2024 15:53
Save Blob as file in JavaScript
// In this file we use a data URL to represent a Blob. This basically base64
// encodes the Blob and puts that string in a URL. This has better compatibility
// with old browsers, but is limited to ~2MB.
const blob = getBlobFromSomewhere()
const reader = new FileReader()
reader.onload = function (event) {
const a = document.createElement('a')
a.href = event.target.result
@jens1101
jens1101 / bootstrap-select-app.js
Last active May 22, 2018 11:38
An angular component wrapper for bootstrap select.
var app = angular.module('app', [])
app.component('selectPicker', {
template: '<div ng-transclude ng-show="$ctrl.show"></div>',
require: {
ngModel: '^ngModel'
},
bindings: {
options: '<',
disable: '<'
@jens1101
jens1101 / ngshow-nghide-use.md
Created January 25, 2017 11:53
Should I use `ng-show` or `ng-hide`?

Often times the choice between both directives seems trivial, because you can achieve the same effect either way. However both have interesting default behaviours that you can use to you advantage.

  • ng-show will hide the element it is on by default, unless the condition in it evaluates to true.
  • ng-hide will show the element it is on by default, unless the condition in it evaluates to true.

This is most useful when your controller is doing AJAX calls or something else that's asynchronous. Your variables may still be undefined until the AJAX call returns.

Example

foo.controller.js

$ctrl.foos;
@jens1101
jens1101 / controller.php
Created October 20, 2016 07:15
Posting data to Codeigniter via pure Angularjs
<?php
class User
{
public function save()
{
$username = $this->input->post('name');
$userData = json_decode($this->input->post('data'));
$doStuff($username, $userData);
}
@jens1101
jens1101 / arrayCopy-es5.js
Created July 28, 2016 09:03
Copy contents of one array into another without breaking references in JS
function arrayCopy(to, from) {
Array.prototype.push.apply(to, from);
}
@jens1101
jens1101 / angular-upload.js
Last active May 22, 2018 09:04
Upload files via AJAX
angular.module('uploadFile', []).service('uploadService', ['$http', function ($http) {
this.uploadFile = function () {
var field = document.createElement('input')
field.setAttribute('type', 'file')
field.setAttribute('accept', '.json, application/json')
field.onchange = function () {
var data = new FormData()
data.append('connectionId', 'banana')
data.append('fileToImport', field.files[0])
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 14, 2024 09:13
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'