Skip to content

Instantly share code, notes, and snippets.

View jimmycann's full-sized avatar

Jimmy Cann jimmycann

View GitHub Profile
@jimmycann
jimmycann / optimal5.go
Created October 3, 2023 07:34
Remove Optimal 5
package main
import (
"fmt"
"strconv"
)
// Receive a number as an argument 15956 for example between the range of -99995 and 99995.
// There are a number of 5s in any given number. For a given number I need to figure out the highest
// possible value of the number when one '5' is removed.
### Keybase proof
I hereby claim:
* I am yjimk on github.
* I am yjimk (https://keybase.io/yjimk) on keybase.
* I have a public key ASD_VLMY_u5GGV8S0vRMoVaA5YHl6Cp0tNb1XnYJLhAgaQo
To claim this, I am signing this object:
@jimmycann
jimmycann / README.md
Created August 2, 2017 22:19
Check for malicious NPM dependencies

Check for malicious dependencies

Take a look through a package.json file for any packages known to be malicious. Will check both the dependencies and devDependencies fields.

Why?

Based on this tweet by @nodesecurity https://twitter.com/nodesecurity/status/892775462371381248, there currently exists a hole where users can publish malicious packages intent on stealing environment variables on install.

A quick one liner to check for these packages, accompanied by more detail on the issue, has been posted by Ivan Akulov at https://iamakulov.com/notes/npm-malicious-packages/. This script has been created for all of our friends on an OS that might not be able to run the command listed.

var crypto = require('crypto')
var elements = ['Hey ', 'Mike']
var hashString = elements.reduce((a, b) => a + b);
console.log('Hash String: ', hashString);
var hashDigest = crypto.createHash('sha256').update(hashString).digest('hex');
console.log('Hash Digest: ', hashDigest);
create: function(data) {
return User.create({
username: data.username,
password: data.password
}).then((result) => {
return Bluebird.resolve(result)
}).catch((err) => {
return Bluebird.reject(err)
})
})
signup: function (req, res) {
User.findOne({
where: {
username: req.body.username
}
}).then(function (user){
if (user) {
sails.log.silly(user);
return res.json(409, { 'error': 'Sorry, that username is already taken' });
@jimmycann
jimmycann / blogFactory.js
Last active May 17, 2016 02:13
AngularJS Factory - $http get
angular.module('app').factory('blogFactory', ['$http',
function ($http) {
//GET all blogs
var get_blogs = function () {
return $http.get('/api/get-blogs')
.then(function(response) {
return response.data; //Flatten the data
});
};
//GET single blog
@jimmycann
jimmycann / routes.js
Created May 17, 2016 02:03
Simple NodeJS API - CRUD using Mongoose
//Keyless - Should be integrated with authentication
//Need to require this file from your Express config using:
//require('./routes.js')(app);
var mongoose = require('mongoose');
var Blog = mongoose.model('blog', {
title: String,
subtitle: String,
img: String,
content: String,
@jimmycann
jimmycann / foursquare-venues-search.php
Created May 17, 2016 01:35
PHP - Retrieve data from the Foursquare venues API
<?php
//Foursquare Venue Search API Sample
//API Documentation available at https://developer.foursquare.com/docs/venues/search
//Retrieve data sent from your application
$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
//This connects to AngularJS, however depending on your application you ay need to retrieve from $_POST
//Required parameter
@jimmycann
jimmycann / datetime.php
Created April 14, 2016 15:04
Convert Custom Date with PHP
<?php
$depart = "140117";
$arrive = "arriving on 21 January 2017";
$dep_date = DateTime::createFromFormat('dmy', $depart);
$arr_date = DateTime::createFromFormat('\a\r\r\i\v\i\n\g \o\n d F Y', $arrive);
$date_diff = $dep_date->diff($arr_date);
$dep_date = $dep_date->format('d-m-Y');