This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #source: https://stackoverflow.com/a/1920585/5405197 | |
| # With Python 2.6+ you can just do: | |
| echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool | |
| #or, if the JSON is in a file, you can do: | |
| python -m json.tool my_json.json | |
| #if the JSON is from an internet source such as an API, you can use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # use this if you want to delete a specific number of entries | |
| # https://stackoverflow.com/questions/13248593/django-database-delete-specific-number-of-entries | |
| HomeImage.objects.filter(pk__in=HomeImage.objects.filter(ImageVectors={}).values_list('pk')[:5000])#.delete() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <iframe src="//www.youtube.com/embed/_youtube_id_" width="560" height="315" frameborder="0" | |
| allowfullscreen="allowfullscreen"> | |
| </iframe> | |
| <iframe class="i-amphtml-fill-content" style="z-index: 0; width: 500px; height: 200px;" | |
| src="https://open.spotify.com/embed/show/0m74ZmCPgjvp5WGOMg3P9C#amp=1" | |
| name="amp_iframe0" width="src=" frameborder="0" sandbox="allow-scripts allow-same-origin"> | |
| </iframe> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- A collection of sample queries in Postgres | |
| -- Get demographic data for users | |
| SELECT gender, Count(*) as genders from dante_userprofile as userprofile | |
| JOIN applications_application as application | |
| ON application.user_id=userprofile.user_id | |
| WHERE application.is_submitted=True | |
| -- WHERE is_finalist=True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rename File Extensions | |
| # https://www.maketecheasier.com/rename-files-in-linux/ | |
| brew install rename; | |
| rename 's/.m4a/.mp3/' * # rename all .m4a files to .mp3 (don't forget to include the asteriks '*') | |
| # delete all files with a certain extension | |
| # https://askubuntu.com/questions/377438/how-can-i-recursively-delete-all-files-of-a-specific-extension-in-the-current-di | |
| find . -name "*.bak" -type f #first check the files that will be deleted | |
| find . -name "*.bak" -type f -delete # then you can delete them |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/main.ts | |
| import { enableProdMode } from '@angular/core'; | |
| import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
| import { AppModule } from './app/app.module'; | |
| import { environment } from './environments/environment'; | |
| if (environment.production) { | |
| enableProdMode(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from botocore.exceptions import ClientError | |
| def dict_to_dynamo(data): | |
| # if you try to save an empty string to dynamo you will get the following error: | |
| # 'An error occurred (ValidationException) when calling the BatchWriteItem operation: One or more parameter values were invalid: An AttributeValue may not contain an empty string' | |
| # This function recursively converts all empty string to valid None/Null type values that dynamo accepts | |
| # https://gist.github.com/JamieCressey/a3a75a397db092d7a70bbe876a6fb817 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Lavar Ball is looking for scholarships to help pay for school. | |
| # He has 2 lists, A and B. | |
| # A is a cache of Lavar's scholarships as an array of primary keys. | |
| # B is an array of scholarship objects matching Lavar's profile. | |
| # Lavar needs to sort the objects in B based on the PKs of A, to get a new B (B_2). | |
| # Lavar needs it done in less than O(n^2) time so he doesn't get bored and starts browsing Reddit. | |
| # e.g. | |
| A = [3,139,47] # arbitrary order | |
| B = [{pk:139,name:'Scholarship X'},{pk:47,name:'Scholarship Y'},{pk:3,name:'Scholarship Z'}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public boolean canFinish(int numCourses, int[][] prerequisites) { | |
| if(prerequisites == null){ | |
| throw new IllegalArgumentException("Invalid Prerequisites"); | |
| } | |
| int p_len = prerequisites.length; | |
| if(p_len == 0||numCourses == 0){ | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyStack<T extends Comparable<T>>{ | |
| private static class StackNode<T extends Comparable<T>> { | |
| private Comparable<T> data; | |
| private StackNode<T> next; | |
| public StackNode(Comparable<T> item){ | |
| this.data =item; | |
| } |