Skip to content

Instantly share code, notes, and snippets.

@samueljseay
samueljseay / es6-import-cheat-sheet.md
Created June 2, 2017 02:35
ES6 exports / imports cheat sheet
// default exports
export default 42;
export default {};
export default [];
export default (1 + 2);
export default foo;
export default function () {}
export default class {}
export default function foo () {}
@vlucas
vlucas / encryption.js
Last active November 15, 2024 01:39
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@hezhao
hezhao / django_cmd.sh
Last active May 1, 2024 07:22
Django Commands Cheatsheet
# Use Python 3 for easy unicode
$ virtualenv -p python3 .env
$ source .env/bin/activate
$ pip install django
$ deactivate
# Start new django project and app
$ django-admin.py startproject mysite
$ ./manage.py migrate
$ ./manage.py createsuperuser
@steffentchr
steffentchr / README.md
Last active July 5, 2018 15:17
An example of how to verify SAML/XML signatures, execute in Ruby. Adapted from https://github.com/zendesk/samlr/.

It's hard to find a good example of how to verify SAML signatures online. There are plenty magic that "just calls a Java method" -- but few clear step-by-step guide.

This gist covers the signature check of a SAML response in Ruby, and as such it's also an example of how to verify an XML Secure.

The code here is lifted entirely from Morten Primdahls and Zendesks awesome SAMLR library.

@slindberg
slindberg / ember-data.dependent-relations.js
Last active November 5, 2021 21:41
Dependent Relationships in Ember Data
/**
Ember Data: Dependent Relationships
This package extends Ember Data to support creating relationships
where a model's dirty state depends not only on its own attributes
but on the dirty state of models in dependent relationships as well.
```javascript
App.Thing = DS.Model.extend({
name : DS.attr('string'),
@iwan
iwan / multiple_action_on_index.md
Last active December 27, 2015 00:09
Get multiple checkboxes in a index view

Routes file (routes.rb):

resources :data_loaders do
  collection do
    delete 'multiple_destroy'
  end
end

The controller:

@pwc3
pwc3 / Exchange Sync.applescript
Last active February 1, 2024 12:34
AppleScript to copy all of the events from an Exchange calendar to an iCloud calendar.
tell application "Calendar"
-- delete everything from the destination calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
repeat with anEvent in (get events of calendar "Destination Calendar")
delete anEvent
end repeat
-- copy all events from the source calendar to the destination
-- TODO: Change "Source Calendar" to be the name of your source calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
@HTMLsauce
HTMLsauce / TODO - TODO.sublime-snippet
Created December 10, 2012 13:49
Sublime Snippet: TODO - TODO
<snippet>
<content><![CDATA[
<!-- TODO: ${1:message} -->
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>to</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@amir20
amir20 / to_csv.rb
Created March 15, 2012 01:10
Converts YAML to CSV
#!/usr/bin/ruby
if ARGV.size.zero?
puts %Q[
Usage:
./to_csv.rb file.yml > out.csv
]
exit
end