Skip to content

Instantly share code, notes, and snippets.

View lentiummmx's full-sized avatar

lentiummmx lentiummmx

View GitHub Profile
@mauricioaniche
mauricioaniche / Basket.java
Created May 19, 2015 02:10
TDD for Professionals - Discount example
package module1.exercise.discount;
import java.util.List;
public class Basket {
private double amount;
private List<Item> items;
public Basket(List<Item> itemss) {
@nicolsc
nicolsc / hex2ascii2hex.js
Created April 10, 2015 16:14
JS hex/ascii
//Thanks stackoverflow
//http://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript
function a2hex(str) {
var arr = [];
for (var i = 0, l = str.length; i < l; i ++) {
var hex = Number(str.charCodeAt(i)).toString(16);
arr.push(hex);
}
return arr.join('');
<?php
$db_con = mysqli_connect("localhost", "username", "password", "database");
$result = $db_con->query('SELECT * FROM some_table');
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysqli_num_fields($result);
$headers = array();
while ($fieldinfo = mysqli_fetch_field($result)) {
$headers[] = $fieldinfo->name;
}
$fp = fopen('php://output', 'w');
@nishantmodak
nishantmodak / nginx.conf.default
Last active April 29, 2025 00:48
Default Nginx Conf
#user nobody;
#Defines which Linux system user will own and run the Nginx server
worker_processes 1;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.
#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.
@Dr4K4n
Dr4K4n / gist:e0a39785f7329f53428d
Created December 11, 2014 17:10
Angular Date period validation
<input type="date" ng-model="reportCtrl.formCtrl.travelFrom" required min="{{ minFromDate | date:'yyyy-MM-dd' }}">
<input type="date" ng-model="reportCtrl.formCtrl.travelTo" required min="{{ reportCtrl.formCtrl.travelFrom | date:'yyyy-MM-dd' }}">
$scope.minFromDate = new Date();
@maxivak
maxivak / 00. tutorial.md
Last active September 11, 2024 19:58
Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler
@RWOverdijk
RWOverdijk / gist:ac3f8bc1d10b7ec5d864
Last active December 22, 2020 10:12
Enable redis sockets on sails.js
module.exports.sockets = {
// Node.js (and consequently Sails.js) apps scale horizontally.
// It's a powerful, efficient approach, but it involves a tiny bit of planning.
// At scale, you'll want to be able to copy your app onto multiple Sails.js servers
// and throw them behind a load balancer.
//
// One of the big challenges of scaling an application is that these sorts of clustered
// deployments cannot share memory, since they are on physically different machines.
// On top of that, there is no guarantee that a user will "stick" with the same server between
// requests (whether HTTP or sockets), since the load balancer will route each request to the
@davideicardi
davideicardi / SmartCollection.js
Last active October 31, 2017 10:22
mongodb library for node.js (Q promise support, schema validation)
var Q = require("q");
//var mongoClient = require("mongodb").MongoClient;
//var ObjectID = require("mongodb").ObjectID;
//var schema = require('validate');
function SmartCollection (mongoDb, collectionName, schema, indexes) {
this._mongoDb = mongoDb;
this._collectionName = collectionName;
this._collection = mongoDb.collection(collectionName);
@colingourlay
colingourlay / example.js
Last active October 22, 2021 15:16
Lodash / Underscore sort object keys. Like _.sortBy(), but on keys instead of values, returning an object, not an array. Defaults to alphanumeric sort.
var obj = {b: 3, c: 2, a: 1};
_.sortKeysBy(obj);
// {a: 1, b: 3, c: 2}
_.sortKeysBy(obj, function (value, key) {
return value;
});
// {a: 1, c: 2, b: 3}
@juanpasolano
juanpasolano / api models Locations.js
Created September 9, 2014 21:50
seed database on sails js
/**
* Locations.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
seedData:[