Skip to content

Instantly share code, notes, and snippets.

@samratshaw
samratshaw / Swift - Storage Manager
Created December 17, 2014 23:02
Storage Options in Swift
/* Printing all values in User Defaults */
println(NSUserDefaults.standardUserDefaults().dictionaryRepresentation());
/* Printing only keys in the User Defaults */
println(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys.array);
/* Printing only keys in the User Defaults */
println(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().values.array);
/* Storing in User Defaults */
@samratshaw
samratshaw / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@samratshaw
samratshaw / javascript_resources.md
Last active August 29, 2015 14:16 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@samratshaw
samratshaw / migrate.sh
Last active October 9, 2023 23:45
Medium: Sequelize migrations with Typescript
# Read arguments passed to the script.
if [ -z "$1" ]; then
ENVIRONMENT='development'
else
ENVIRONMENT="$1"
fi
echo ""
echo "Migrating for environment: $ENVIRONMENT"
echo ""
@samratshaw
samratshaw / config.js
Created July 30, 2018 09:47
Medium: Sequelize configuration
const fs = require('fs');
module.exports = {
development: {
url: 'postgres://postgres@localhost:5432/devopsjourney',
dialect: 'postgres',
operatorsAliases: false,
},
production: {
url: process.env.DB_URL,
@samratshaw
samratshaw / .sequelizerc
Last active September 26, 2018 02:04
Medium: Sequelize Typescript config
const path = require('path');
module.exports = {
config: path.resolve('src', 'db', 'config.js'),
'models-path': path.resolve('src', 'db', 'models'),
'seeders-path': path.resolve('src', 'db', 'seeders'),
'migrations-path': path.resolve('build-migrations', 'db', 'migrations'),
};
@samratshaw
samratshaw / migration-generate.sh
Created July 30, 2018 09:50
Medium: Sequelize Typescript create migration
cat > ./src/db/migrations/$(date +"%Y%m%d%H%M%S")-$1.ts << EOF
import { QueryInterface, SequelizeStatic } from 'sequelize';
module.exports = {
// tslint:disable-next-line:variable-name
up: async (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
// Write migration code here.
},
// tslint:disable-next-line:variable-name
@samratshaw
samratshaw / getJenkinsApiToken.ts
Last active May 21, 2019 05:57
Medium: Function for retrieving the Jenkins Api Token
import * as request from 'request';
import * as fs from 'fs';
import * as cheerio from 'cheerio';
/**
* Retrieve the Jenkins Api Token.
*/
async function getJenkinsApiToken(): Promise<string> {
return new Promise<string>((resolve, reject) => {
request(
@samratshaw
samratshaw / jenkins-username-password-authentication-api
Created September 12, 2018 14:47
Medium: Curl showing the Jenkins Authentication API (Using Username & Password)
curl -X POST JENKINS_URL/job/JOB_NAME/build \
--user <USER:PASSWORD> \
--data-urlencode json='{"parameter": [{"name":"id", "value":"123"}]}'
@samratshaw
samratshaw / jenkins-token-authentication-api
Created September 12, 2018 14:47
Medium: Curl showing the Jenkins Authentication API (Using Token)
curl -X POST JENKINS_URL/job/JOB_NAME/build \
--user <USER:TOKEN> \
--data-urlencode json='{"parameter": [{"name":"id", "value":"123"}]}'